我有一个字符串如下:
str1 = "heylisten\uff08there is something\uff09to say \uffa9"
我需要用两边的空格替换正则表达式检测到的unicode值。你知道吗
所需输出字符串:
out = "heylisten \uff08 there is something \uff09 to say \uffa9 "
我用了一个关于芬德尔把所有的火柴都拿出来然后换掉。它看起来像:
p1 = re.findall(r'\uff[0-9a-e][0-9]', str1, flags = re.U)
out = str1
for item in p1:
print item
print out
out= re.sub(item, r" " + item + r" ", out)
输出:
'heylisten\\ uff08 there is something\\ uff09 to say \\ uffa9 '
上面的方法打印一个额外的“\”并将其与uff
分开,这有什么错?我甚至试过用re.search
但是它似乎只分开\uff08
。有更好的办法吗?你知道吗
您没有任何unicode值。你有一个备用环。你知道吗
您可以直接使用这个
re.sub
。请参见演示。你知道吗http://regex101.com/r/sU3fA2/67
输出:
相关问题 更多 >
编程相关推荐