下面的模式花了我很長時間才發現。當我終於找到它時,事實證明它在Python中不起作用。有誰知道是否有替代方案?PCRE正則表達式(* COMMIT)等效於Python
(*COMMIT)
定義:如果模式的其餘部分不匹配,則會導致整個匹配失敗。
(*FAIL)
在Python中也不起作用。但是這可以由(?!)
取代。取自
+-----------------------------------------------+
|Pattern: |
|^.*park(*COMMIT)(*FAIL)|dog |
+-------------------------------------+---------+
|Subject | Matches |
+-----------------------------------------------+
|The dog and the man play in the park.| FALSE |
|Man I love that dog! | TRUE |
|I'm dog tired | TRUE |
|The dog park is no place for man. | FALSE |
|park next to this dog's man. | FALSE |
+-------------------------------------+---------+
例子: regex match substring unless another substring matches
您可以執行r(^!。 8qDQDG/1) – dawg
該正則表達式在PCRE中也不起作用;你修改它的答案是錯誤的。但是,沒關係控制動詞,lookaheads在兩種口味中都能正常工作,正如[Sebastian的回答](http://stackoverflow.com/a/39796696/20938)所示。 –