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

Small error in Regular expression operations module #131494

Closed
Mindiell opened this issue Mar 20, 2025 · 2 comments
Closed

Small error in Regular expression operations module #131494

Mindiell opened this issue Mar 20, 2025 · 2 comments
Labels
docs Documentation in the Doc dir

Comments

@Mindiell
Copy link

Documentation

In positive lookbehind assertion (?<=...), the second example has an error on its explanation:

It says "This example looks for a word following a hyphen:"

It should say "This example looks for a word followed by a hyphen:"

@Mindiell Mindiell added the docs Documentation in the Doc dir label Mar 20, 2025
@brianschubert
Copy link
Contributor

This is the example in question:

>>> m = re.search(r'(?<=-)\w+', 'spam-egg')
>>> m.group(0)
'egg'

I think the explanation in the docs is correct as written. The regex (?<=-)\w+ matches a word immediately preceded by a hyphen. In the example, the matched text 'egg' is the word directly following the hyphen in 'spam-egg'. The pattern for “a word followed by a hyphen” would be a lookahead, not a lookbehind, and would be written something like \w+(?=-).

@Mindiell
Copy link
Author

Woups! That's true, the error is in the french translation. I looked at the original one and thought it was false too.
My mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

2 participants