我正在尝试使用python中的正则表达式从文本中删除特定的双引号。我只想保留表示英寸的双引号。因此,这意味着在数字后留下任何双引号。
txt = 'measurement 1/2" and 3" "remove" end" a " multiple"""
Expected output:
measurement 1/2" and 3" remove end a multiple
这是我最近的。
re.sub(r'[^(?!\d+/\d+")]"+', '', txt)
我正在尝试使用python中的正则表达式从文本中删除特定的双引号。我只想保留表示英寸的双引号。因此,这意味着在数字后留下任何双引号。
txt = 'measurement 1/2" and 3" "remove" end" a " multiple"""
Expected output:
measurement 1/2" and 3" remove end a multiple
这是我最近的。
re.sub(r'[^(?!\d+/\d+")]"+', '', txt)
只需使用
See a demo on regex101.com.
basically meant not
(
,?
,!
, etc.