[Solved] python re.compile match dosn’t match backward slash in full path in windows [duplicate]


So there are two things:

  1. The assignment of s should be either with escaped back-slashes or as a raw string. I prefer the latter:
s = r"C:\x\xxx\temp\downloads\test_dir\sql\my-ee.sql" 
  1. you should use the search method instead of match to be content with a partial match.

Then, you can use \\\\ in the regular expression, or – as I prefer – a raw string again:

import re

regex1 = re.compile(r'downloads\\test_dir\\sql\\my-ee.sql')  
s = r"C:\x\xxx\temp\downloads\test_dir\sql\my-ee.sql"  
gg = regex1.search(s)
print(gg)

0

solved python re.compile match dosn’t match backward slash in full path in windows [duplicate]