gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 22:49:19 29 4
gpt4 key购买 nike

来自 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com