在分析推文时,我遇到了带有\或/的“单词”(一个“单词”中可能会出现多个)。我希望完全删除这些单词,但却无法完全解决问题。
这是我尝试过的方法:
补充说明:在这种情况下,“单词”是由空格或标点符号(如普通文本)分隔的字符串。
这是我尝试过的方法:
sen = 'this is \re\store and b\\fre'
sen1 = 'this i\s /re/store and b//fre/'
slash_back = r'(?:[\w_]+\\[\w_]+)'
slash_fwd = r'(?:[\w_]+/+[\w_]+)'
slash_all = r'(?<!\S)[a-z-]+(?=[,.!?:;]?(?!\S))'
strt = re.sub(slash_back,"",sen)
strt1 = re.sub(slash_fwd,"",sen1)
strt2 = re.sub(slash_all,"",sen1)
print strt
print strt1
print strt2
我想获取:
this is and
this i\s and
this and
然而,我收到:
and
this i\s / and /
i\s /re/store b//fre/
补充说明:在这种情况下,“单词”是由空格或标点符号(如普通文本)分隔的字符串。