【发布时间】:2021-02-22 20:29:17
【问题描述】:
我有一大段文本,下面是其中的一个示例。
'tis too true! How smart a lash that
speech doth give my conscience! The harlot's cheek beautied with plastering art Is not more ugly to the thing
我想去掉所有不是“.?!”的标点符号。我想我是用下面的代码这样做的:
hamsplits2 = re.sub(r'[^[a-z.?!\s]]', "", hamsplits1) # substitute any character that is not what's in box
但代码似乎不起作用,因为当我 print(hamsplits2) 时,我仍然得到撇号和破折号。
how smart a lash that
speech doth give my conscience! the harlot's cheek beautied with plastering art is not more ugly to the
我的正则表达式有什么问题导致它无法删除撇号和破折号?
【问题讨论】:
标签: python regex punctuation