【发布时间】:2020-09-08 05:53:08
【问题描述】:
我正在尝试使用下面的正则表达式来查找“|”之后的任何数字运算符来处理下面的一些示例字符串。问题在于默认的正则表达式,我似乎无法将 numeric_regex 与 Lookbehind 结合起来。
'xxx -> 31223.1 | xxx -> 1.1'. to get 1.1
'0 | 1' to get 1
numeric_regex = '''
[-+]? # pos or neg
(?: (?: \d* \. \d+ ) | # float (ie .1 and 1.1)
(?: \d+ \.? ) ) # int (with trailing periods ie 1.)
'''
default_regex = f'''
(? <= \|). # after but not including |
{numeric_regex} # all digits
+ $ # end of the string
'''
任何帮助表示赞赏!
【问题讨论】:
-
嗨,Tommy,这两个答案对您解决问题有帮助吗?