ITHO博客

从网络安全入门到放弃

python间隔两个字符串插入一个字符

2022-5-13 myluzh 二维码 程序开发

import re

subject = '080045000106309140003F2F7D100A01'

if (len(subject) % 2) == 0:
    result = re.sub(r"(?<=\w)(?=(?:\w\w)+$)", "-", subject)
elif (len(subject) % 2) != 0:
    a_subject = subject[:-1]
    b_subject = subject[-1]
    result = re.sub(r"(?<=\w)(?=(?:\w\w)+$)", "-", a_subject) + "-" + b_subject

print(result)
输出内容 08-00-45-00-01-06-30-91-40-00-3F-2F-7D-10-0A-01 

标签: python

发表评论