use*_*990 10 python regex list
我有数据框,其中txt
列包含一个列表.我想txt
使用函数clean_text()清理列.
data = {'value':['abc.txt', 'cda.txt'], 'txt':['[''2019/01/31-11:56:23.288258 1886 7F0ED4CDC704 asfasnfs: remove datepart'']',
'[''2019/02/01-11:56:23.288258 1886 7F0ED4CDC704 asfasnfs: remove datepart'']']}
df = pandas.DataFrame(data=data)
def clean_text(text):
"""
:param text: it is the plain text
:return: cleaned text
"""
patterns = [r"^{53}",
r"[A-Za-z]+[\d]+[\w]*|[\d]+[A-Za-z]+[\w]*",
r"[-=/':,?${}\[\]-_()>.~" ";+]"]
for p in patterns:
text = re.sub(p, '', text)
return text
Run Code Online (Sandbox Code Playgroud)
我的解决方案:
df['txt'] = df['txt'].apply(lambda x: clean_text(x))
Run Code Online (Sandbox Code Playgroud)
但我得到以下错误: 错误
sre_constants.error: nothing to repeat at position 1
Run Code Online (Sandbox Code Playgroud)
blh*_*ing 10
^{53}
不是有效的正则表达式,因为转发器{53}
前面必须有可重复的字符或模式.如果您要使其验证长度至少为53个字符的字符串,则可以使用以下模式:
^.{53}
Run Code Online (Sandbox Code Playgroud)