[issue42885] Optimize re.search() for \A (and maybe ^)

2022-03-22 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- resolution: -> fixed stage: patch review -> resolved status: open -> closed ___ Python tracker ___

[issue42885] Optimize re.search() for \A (and maybe ^)

2022-03-22 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: New changeset 492d4109f4d953c478cb48f17aa32adbb912623b by Serhiy Storchaka in branch 'main': bpo-42885: Optimize search for regular expressions starting with "\A" or "^" (GH-32021) https://github.com/python/cpython/commit/492d4109f4d953c478cb48f17aa32adbb9

[issue42885] Optimize re.search() for \A (and maybe ^)

2022-03-20 Thread Serhiy Storchaka
Change by Serhiy Storchaka : -- keywords: +patch pull_requests: +30109 stage: -> patch review pull_request: https://github.com/python/cpython/pull/32021 ___ Python tracker ___

[issue42885] Optimize re.search() for \A (and maybe ^)

2021-01-16 Thread Arnim Rupp
Change by Arnim Rupp : -- components: +Regular Expressions -Library (Lib) nosy: +ezio.melotti, mrabarnett ___ Python tracker ___ ___

[issue42885] Optimize re.search() for \A (and maybe ^)

2021-01-16 Thread Arnim Rupp
Arnim Rupp added the comment: some more observations, which might be helpful in tracking it down: x$ is much faster than ^x A$ is as slow as ^x $ python3 -m timeit -s "a = 'A'*1" "import re" "re.search('x$', a)" 10 loops, best of 5: 32.9 msec per loop $ python3 -m timeit -s "a = 'A'*

[issue42885] Optimize re.search() for \A (and maybe ^)

2021-01-16 Thread Steven D'Aprano
Steven D'Aprano added the comment: On Sat, Jan 16, 2021 at 08:59:13AM +, Serhiy Storchaka wrote: > > Serhiy Storchaka added the comment: > > ^ matches not just the beginning of the string. It matches the > beginning of a line, i.e. an anchor just after '\n'. Only in MULTILINE mode. I

[issue42885] Optimize re.search() for \A (and maybe ^)

2021-01-16 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: ^ matches not just the beginning of the string. It matches the beginning of a line, i.e. an anchor just after '\n'. If the input string contains '\n', the result cannot be found less than by linear time. If you want to check if the beginning of the string