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

Default word regex and snake_case checking #2979

Closed
DimitriPapadopoulos opened this issue Jul 28, 2023 · 3 comments
Closed

Default word regex and snake_case checking #2979

DimitriPapadopoulos opened this issue Jul 28, 2023 · 3 comments

Comments

@DimitriPapadopoulos
Copy link
Collaborator

DimitriPapadopoulos commented Jul 28, 2023

The underscore (_) is part of \w. From https://docs.python.org/3/library/re.html#regular-expression-syntax:

\w

For Unicode (str) patterns:
Matches Unicode word characters; this includes alphanumeric characters (as defined by str.isalnum()) as well as the underscore (_). If the ASCII flag is used, only [a-zA-Z0-9_] is matched.

For 8-bit (bytes) patterns:
Matches characters considered alphanumeric in the ASCII character set; this is equivalent to [a-zA-Z0-9_]. If the LOCALE flag is used, matches characters considered alphanumeric in the current locale and the underscore.

Is there an easy way to get \w except _ in the non-ASCII case? It would help checking snake_case.

word_regex_def = "[\\w\\-'’`]+"

@DimitriPapadopoulos
Copy link
Collaborator Author

Unicode regexes with set operations might help, but they are not available in Python yet. From https://docs.python.org/3/library/re.html#regular-expression-syntax:

  • Support of nested sets and set operations as in Unicode Technical Standard #18 might be added in the future. This would change the syntax, so to facilitate this change a FutureWarning will be raised in ambiguous cases for the time being. That includes sets starting with a literal '[' or containing literal character sequences '--', '&&', '~~', and '||'. To avoid a warning escape them with a backslash.

@DimitriPapadopoulos
Copy link
Collaborator Author

@DimitriPapadopoulos DimitriPapadopoulos changed the title Default word regex and snake_case checking Default word regex and **snake_case** checking Jul 28, 2023
@DimitriPapadopoulos DimitriPapadopoulos changed the title Default word regex and **snake_case** checking Default word regex and snake_case checking Jul 28, 2023
@DimitriPapadopoulos
Copy link
Collaborator Author

Duplicate of #2730.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant