PCRE Regex (*COMMIT) equivalent for Python
<p>The below pattern took me a long time to find. When I finally found it, it turns out that it doesn't work in Python. Does anyone know if there is an alternative?</p>

<p><code>(*COMMIT)</code> Defined: Causes the whole match to fail outright if the rest of the pattern does not match.</p>

<p><code>(*FAIL)</code> doesn't work in Python either. But this can be replaced by <code>(?!)</code>.</p>

<pre><code>+-----------------------------------------------+
|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  |
+-------------------------------------+---------+
</code></pre>

<p>Example taken from:
<a href="http://stackoverflow.com/questions/32747887/regex-match-substring-unless-another-substring-matches/39795732#39795732">regex match substring unless another substring matches</a></p>

<p>This might not be a generic replacement, but for your case you can work with lookaheads, to assert that dog is matched, but park is not: <code>^(?=.*dog)(?!.*park).*$</code></p>

<p>Your samples on <a href="https://regex101.com/r/gOY9GT/1" rel="nofollow">regex101</a></p>

python regex