问题标签 [pypi-regex]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
python - 即使没有前瞻,添加一些文本如何使这个正则表达式匹配输入?
在回答这个问题时,我想出了这个正则表达式:
(注意:这个正则表达式需要PyPIregex
模块)
(简短的解释:正则表达式依赖于这样一个事实,即前瞻中的捕获组在匹配一次后无法更改其值,因此在foo=
找到第一个后,(?=())
匹配以及从那时起(?!\2)
将始终失败。)
此正则表达式适用于问题中给出的 2 个示例:
但是如果出现foo=
after a ,就会发生一些奇怪的事情bar=2
:
如您所见,字符串'notfoo=1,bar=2,foo=3,'
产生了notfoo=1,bar=2
. 甚至不包含在匹配中,但是如果将foo=3,
其删除,则正则表达式将不再匹配!这怎么可能?这是regex
模块中的错误吗?