Python 正则表达式 : how to do a negative lookahead with a string which don't start immediately?

标签 python regex python-2.7

来自https://docs.python.org/2/library/re.html#regular-expression-syntax :

(?!...)
Matches if ... doesn’t match next. This is a negative lookahead assertion. For example, Isaac (?!Asimov) will match 'Isaac ' only if it’s not followed by 'Asimov'.

但是如果IsaacAsimov之间有一个或多个单词怎么办?

最佳答案

Isaac(?!.*Asimov)

对以 Asimov 结尾的任何字符序列使用负前瞻。如果您想在 . 中包含换行符,[\s\S]DOTALL 标志可能比较合适。

关于Python 正则表达式 : how to do a negative lookahead with a string which don't start immediately?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23946398/

相关文章:

python - 关于 yolov2 损失函数的问题?

python - Pygame - Sprite 与 Sprite 组的碰撞

python - 类型错误 : translate() takes exactly one argument (2 given)

python - 如何动态地为 Python 中的类属性赋值?

python - 如何将 Django Rest Framework 与 contrib.auth View 连接

python - 解包十六进制编码的 float

python - Matplotlib 3d 线框图未按预期绘制

javascript - 如果超过 10 个,请移除

c# - 正则表达式忽略嵌套分隔符上的匹配

java - java Dash 版本中 unicode 的正则表达式