Reputation: 96837
I want to test if a method appears in a header file. These are the three cases I have:
void aMethod(params ...)
//void aMethod(params
// void aMethod(params
^ can have any number of spaces here
Here's what I have so far:
re.search("(?<!\/\/)\s*void aMethod",buffer)
Buf this will only match the first case, and the second. How could I tweak it to have it match the third too?
EDIT:sorry, but I didn't express myself correctly. I only want to match if not within a comment. So sorry.
Upvotes: 0
Views: 111
Reputation: 2170
EDIT: Ok, after your edit, Geo, it is this:
^(?<!\/\/)\s*void aMethod
Upvotes: 7
Reputation: 29111
If you simply want to find all appearances for 'void aMethod(params' then you can use the following:
a = """void aMethod(params ...)
//void aMethod(params
// void aMethod(params
^ can have any number of spaces here"""
from re import findall
findall(r'\bvoid aMethod\b', a)
OR:
findall(r'(?:\/\/)?[ ]*void aMethod', a)
Upvotes: 2