【发布时间】:2020-09-08 19:45:10
【问题描述】:
如何使用 Regex 获取不在两个其他字符/单词之间的字符/单词?
例如,在:
hello world [hello hello] world hello [world hello world hello] world hello [hello] hello
它会选择:
你好世界[你好你好]世界你好[世界你好世界你好]世界你好[你好]你好
This question 获取文本,而不是两个字符之间 ((?<=^|\])[^[]+),这很接近,除此之外,所有需要做的就是从中选择特定的单词。
【问题讨论】:
-
您可以使用捕获组
\[[^][]*]|\b(hello)\bregex101.com/r/3BXpYf/1 查看ideone.com/PP0QM5
标签: python regex regex-negation