Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python lint issue : invalid escape sequence '\/'

This is my python code line which is giving me invalid escape sequence ‘/’ lint issue.

pattern = 'gs:\/\/([a-z0-9-]+)\/(.+)$'  # for regex matching

It is giving me out that error for all the backslash I used here .
any idea how to resolve this ?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

There’s two issues here:

  1. Since this is not a raw string, the backslashes are string escapes, not regexp escapes. Since \/ is not a valid string escape sequence, you get that warning. Use a raw string so that the backslashes will be ignored by the string parser and passed to the regexp engine. See What exactly is a "raw string regex" and how can you use it?
  2. In some languages / is part of the regular expression syntax (it’s the delimiter around the regexp), so they need to be escaped. But Python doesn’t use / this way, so there’s no need to escape them in the first place.

Use this:

pattern = r'gs://([a-z0-9-]+)/(.+)$'  # for regex matching
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading