Could anybody please answer this? I'm trying to learn reg expression (re) module and I'm not able to get my head around this one. I'm trying to come up regex to catch all 3 file name formats
Python 3.4.3
>>> re.findall("file[\_-]1","file-1 file_1, file\1") ['file-1', 'file_1'] >>> Why isn't it catching file\1?? I did try two other patterns, neither one worked :(
1. re.findall("file[\\_-]1","file-1 file_1, file\1") 2. re.findall(r"file[\_-]1","file-1 file_1, file\1") Thanks, Sagar
\1in "file\1" is a control character\u0001;. If you really plan to capture it, useprint (re.findall("file[\u0001_-]1?","file-1 file_1, file\1")), but I doubt you need it.