Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python ^ semantics wrong (don't match PCRE2) #2274

Open
NWilson opened this issue May 7, 2024 · 0 comments
Open

Python ^ semantics wrong (don't match PCRE2) #2274

NWilson opened this issue May 7, 2024 · 0 comments
Labels

Comments

@NWilson
Copy link

NWilson commented May 7, 2024

Bug Description

Python's meaning of ^ is "start of string, or in /m mode after any newline".
This is different to PCRE2's default meaning for ^, which is "start of string, or in /m mode after newlines which are not the last character in the file".

You are using PCRE2 I believe to emulate Python support? You need to set PCRE2_ALT_CIRCUMFLEX to get behaviour matching Python.

Reproduction steps

  1. Switch Regex101 to Python mode, with r"..."gm flags
  2. Use the regex ^$
  3. Use the text "a<trailing newline>"

Expected Outcome

Python produces one match. Regex101 reports zero matches (same as PCRE2)

Verification:

import re
print( re.search(r"^$", "a\n", re.M) )

Browser

Include browser name and version

OS

Include OS name and version

@NWilson NWilson added the bug label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant