regex - Python match string if it does not start with X -
I want to find a file named "AcroTray.exe" on my disk. The program should print a warning if the file is located in any directory other than "distiller" I used the following syntax to match the negative The problem is that though I "!" It always creates a match. I tried to understand the problem of using the eyewitness, but failed. This is what I tried to do: This prints a match What's wrong with my regex? I would like to get a match: but not: negative Look-up ( This mail: This does not match:
(? ! Distillr)
import re filePath = "C: \ Distillr \ AcroTray.exe" If re.search (r '(!! Distillr) \\ AcroTray \ .exe 'FilePath): Print "Match"
C: \ SomeDir \ AcroTray.exe
c: \ distillr \ acroTray.exe
(? & Lt ;! ... ), do not look at the negatives:
if re.search ( R '(? & Lt;! Distillr) \\ AcroTray \ .exe, filePath):
in [45] ]: Re-search (R '(? & Lt ;! Distiller) \\ AcroTray \ .exe', r'C: \ SomeDir \ AcroTray.exe ') Out [45]: & lt; _sre.SRE_Match 0xb57f448 & gt;
in
[46] ]: Re.search (r '(? & Lt ;! Distillr) \\ AcroTray \ .exe', R'C: \ Distillr \ AcroTray.exe ') # None
Comments
Post a Comment