Skip to content

Commit

Permalink
pythongh-106566: Optimize (?!) in regeular expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Jul 9, 2023
1 parent 8cb6f97 commit 46577c4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Lib/re/_parser.py
Expand Up @@ -773,8 +773,10 @@ def _parse(source, state, verbose, nested, first=False):
source.tell() - start)
if char == "=":
subpatternappend((ASSERT, (dir, p)))
else:
elif p:
subpatternappend((ASSERT_NOT, (dir, p)))
else:
subpatternappend((FAILURE, ()))
continue

elif char == "(":
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_re.py
Expand Up @@ -2362,6 +2362,9 @@ def test_regression_gh94675(self):
p.terminate()
p.join()

def test_fail(self):
self.assertEqual(re.search(r'12(?!)|3', '123')[0], '3')


def get_debug_out(pat):
with captured_stdout() as out:
Expand Down
@@ -0,0 +1 @@
Optimize ``(?!)`` (pattern which alwais fails) in regular expressions.

0 comments on commit 46577c4

Please sign in to comment.