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
regex howto example in "Lookahead Assertions" #69703
Comments
The example advises ".*..*$" expression "to match filenames where the extension is not bat". But here is an example which passes such check: >>> re.match("(.*)[.](?!bat$).*$", "test.a.bat")
<_sre.SRE_Match object at 0x7ff221996f30> To my mind use of negative lookbehind expressions (not covered so far in the HOWTO) is better:
|
Note that lookbehind assertions still are not documented in Regular Expression HOWTO. The example that demonstrates negative lookahead assertion is ".*.[^.]$". But then we should explain why ".*" is changed to "[^.]". |
Corrected the regular expression and documented why [^.]* is used. |
New changeset c6b5c03183e3 by Ezio Melotti in branch '2.7': New changeset 6bd4a4907f66 by Ezio Melotti in branch '3.5': New changeset 48e2f5915d49 by Ezio Melotti in branch 'default': |
Fixed, thanks for the patch! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: