Hello! I need help to construct a regular expression in Python that will help me get the file name of a include directive in C++. I think that regular expressions are a good way to solve this problem, but I'm open to new ideas.
Consider these following includes:
#include "hello.h" #include "d/hello.h" #include "dir/hello.h" #include "dir\hello.h" #include <hello.h> #include "a\b\c.h" #include <ref\six\eight.h> #include "123\456/789.h" #include "bye.h"
In all these cases, I want the name of the included file (for example, hello.h, c.h, eight.h, 789.h and bye.h). I have written a regular expression that's not working (I think). Here it is:
fileNamePattern = re.compile(r""" [\\/"<] #The last part of the include file path begins with these characters." [a-zA-Z0-9_]+ [>"] #The end of include line must end with > or " (\s)* #Any whitespace character (including tabs, carriage returns) $ #The end of the string. """, re.VERBOSE)
I'm calling the groups() method on every match and on every string passed, it returns None (means that none of the strings match this regular expression).
Can you help me make a regular expression work with my case?
Thanks in advance.