Python Regex:获取除字符串之外的所有内容

时间:2013-08-20 04:01:10

标签: python regex

我有以下句子:

Graft Concepts has partnered with\u00a0several sites\u00a0to offer customization options for backplates, so customers will be able to design their own with\u00a0 

我想摆脱所有“\ u00a0”的实例,无论它们是否与其他单词相关联,例如“与\ u00a0several”

如何使用python的正则表达式执行此操作?我已经尝试过使用re.compile()和re.findall()进行实验,但是我无法使用它?

感谢。

2 个答案:

答案 0 :(得分:6)

您可以使用.replace

s = s.replace('\\u00a0', ' ')

答案 1 :(得分:0)

这适用于Python 2:

import re

st='''Graft Concepts has partnered with\u00a0several sites\u00a0to offer customization options for backplates, so customers will be able to design their own with\u00a0''' 

st=re.sub(ur'\\u00a0','',st,re.UNICODE)

这在Python 3下:

st=re.sub(u'\\u00a0','',st,re.UNICODE)