Skip to content

SyntaxWarning from invalid escape sequences in regex patterns (Python 3.12+) #350

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

Open
SR-Rubel opened this issue May 11, 2025 · 0 comments · May be fixed by #351
Open

SyntaxWarning from invalid escape sequences in regex patterns (Python 3.12+) #350

SR-Rubel opened this issue May 11, 2025 · 0 comments · May be fixed by #351

Comments

@SR-Rubel
Copy link

While using nlpaug with Python 3.12, the following warning is raised due to invalid escape sequences in string literals used for regular expressions:

SyntaxWarning: invalid escape sequence '\s'
  prefix_reg = '(?<=\s|\W)'
SyntaxWarning: invalid escape sequence '\s'
  suffix_reg = '(?=\s|\W)'

These warnings originate from the context_word_embs.py file and are due to the use of unescaped backslashes in non-raw strings.

File Affected:
nlpaug/augmenter/word/context_word_embs.py, lines 123–124.

Why This Matters:

  • Raw strings are the recommended way to write regular expressions in Python.
  • Python 3.12+ raises SyntaxWarning for escape sequences that don’t have a clear meaning, and future versions may turn this into a SyntaxError.
  • Fixing this improves compatibility and eliminates noisy warnings for users.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant