Skip to content

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

@SR-Rubel

Description

@SR-Rubel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions