我如何制作像 "(.*)"
这样的 python 正则表达式,这样,给定 "a (b) c (d) e"
python 匹配 "b"
而不是 "b) c (d"
?
我知道我可以使用 "[^)]"
而不是 "."
,但我正在寻找一种更通用的解决方案,让我的正则表达式小清洁工。有没有办法告诉python“嘿,尽快匹配这个”?
最佳答案
你寻求全能的*?
the non-greedy qualifiers
*?
,+?
,??
, or{m,n}?
[...] match as little text as possible.
关于Python 非贪婪正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/766372/