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

python: fix regex strings #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MaxGyver83
Copy link

Use raw strings to get rid of these warnings:

$ python vim-plugins-profile.py
/tmp/vim-plugins-profile.py:105: SyntaxWarning: invalid escape sequence '\d'
  matches = re.findall("^\d+.\d+\s+\d+.\d+\s+\d+.\d+: "
/tmp/vim-plugins-profile.py:132: SyntaxWarning: invalid escape sequence '\d'
  matches = re.findall("^\d+.\d+\s+\d+.\d+\s+(\d+.\d+): "
/tmp/vim-plugins-profile.py:151: SyntaxWarning: invalid escape sequence '\d'
  matches = re.findall("^\d+.\d+\s+\d+.\d+\s+(\d+.\d+): "
Running vim to generate startup logs... done.
...

The solution is to use Python’s raw string notation for regular expression patterns; backslashes are not handled in any special way in a string literal prefixed with 'r'. So r"\n" is a two-character string containing '\' and 'n', while "\n" is a one-character string containing a newline. Usually patterns will be expressed in Python code using this raw string notation.

re — Regular expression operations — Python 3.13.0 documentation

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 this pull request may close these issues.

1 participant