[英]Using regex in python to remove double quotes with exclusions
我正在尝试使用 python 中的正则表达式从文本中删除特定的双引号。 我只想留下那些表示英寸的双引号。 所以这意味着在数字后面留下任何双引号。
txt = 'measurement 1/2" and 3" "remove" end" a " multiple"""
预期的 output: measurement 1/2" and 3" remove end a multiple
这是我得到的最接近的。
re.sub(r'[^(?,\d+/\d+")]"+', '', txt)
只需使用
(?<!\d)"+
[^(?!\d+/\d+")]
基本上意味着不是(
, ?
, !
等。
regex
模块与(*SKIP)(*FAIL)
一起使用:
measurement 1/2" and 3" remove end a multiple
ABC2DEF3
这会产生
measurement 1/2" and 3" remove end a multiple ABC2DEF3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.