I have to extract file ID from file links. The file link is similar to this example "\abc.xyz\folder1\folder2\folder3\folder5 \F-17-50021\OE \abc\xyz\file.xlsm" (bold part remains the same in every link). I decided to use regex to extract the file ID as there is a fixed pattern. I tried using the code below.
p = "Antartica"
re.search("n(.*)c",p).group(1)
It gives the output 'tarti' which is fine. I created a same regex to extract the file ID but it's not working.
p = r"\\abc.xyz\folder1\folder2\folder3\folder5\F-17-50021\OE\abc\xyz\file.xlsm"
re.search('\(.*)\OE', p).group(1)
I'm getting an error in mentioning "'NoneType' object has no attribute 'group'".
Please explain what is wrong in my code. How can I make it work?
TIA
"in your input string.Nonefromre.search(...)this is the case when that doesn't find a pattern match. like @WiktorStribiżew stated you are looking for"characters in your pattern and they do not exist. Also consider usingos.path.split()for a more robust cross-platform solution.