python 正则 中英文之间加空格

原创博文 转载请注明出处!

import re

string = input("要转换的字符串: ")
pattern = re.compile(r'([A-Za-z’!"#$%&\'()*+,-./:;<=>?@]{0,})([\u4e00-\u9fa5\u3002\uff1b\uff0c\uff1a\u201c\u201d\uff08\uff09\u3001\uff1f\u300a\u300b]{1,})')
find_list = pattern.findall(string)

lis = [x[0]+' '+x[1] for x in find_list]
s = ' '.join(lis)
print('\n装换后的字符串:\n')
print(s.strip())

猜你喜欢

转载自www.cnblogs.com/JanSN/p/10572679.html