This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients 2d4d, serhiy.storchaka, steven.daprano
Date 2021-01-16.08:59:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1610787553.89.0.699530326868.issue42885@roundup.psfhosted.org>
In-reply-to
Content
^ 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 matches a regular expression, it is better to use match(). If you want the check if the whole string matches it, it is better to use fullmatch().

But in some cases you cannot choose what method to use. If you have a set of patterns, and only some of them should be anchored to the start of the string, you have to use search(). And while linear complexity for ^ is expected, search() is not optimized for \A.

So the original report is rejected, the behavior is expected and cannot be changed. It is not a bug. But some optimization can be added for \A, and perhaps the constant multiplier for ^ can be reduced too.
History
Date User Action Args
2021-01-16 08:59:13serhiy.storchakasetrecipients: + serhiy.storchaka, steven.daprano, 2d4d
2021-01-16 08:59:13serhiy.storchakasetmessageid: <1610787553.89.0.699530326868.issue42885@roundup.psfhosted.org>
2021-01-16 08:59:13serhiy.storchakalinkissue42885 messages
2021-01-16 08:59:13serhiy.storchakacreate