regular expression
Posted
by Altariste
on Stack Overflow
See other posts from Stack Overflow
or by Altariste
Published on 2010-06-14T14:14:21Z
Indexed on
2010/06/14
14:22 UTC
Read the original article
Hit count: 160
Hi,
I need to find all invocations of some logging macros in the code. The macro invocation is of the form:
DEBUG[1-5] ( "methodName: the logged message", arguments)
But the new versions of the macros are prepending the name of the method automatically, so my task is to write a Python script that will remove the duplicate function names specified already by the programmer.
I'm using the sub function from the re module. I plan to substitute the part indicated by || signs below :
||DEBUG[1-5] ("methodName: || the logged message", arguments)
with simplyDEBUG[1-5]("
The problem is following:
To find the expressions I want to substitute, I use the following regular expression:
((DEBUG | INFO | all other macros names )[1-5]*)\s*\(\"\w+:
But it doesn't match the whole expression ( from DEBUG right to the colon ), but only the macro name, that is for example DEBUG5.
Is my expression wrong or there is some quirk in the Python regex processing? ( maybe the fact that I use the DEBUG[1-5] as a subgroup has something to do with this? ) Help from anyone more knowledgable than me appreciated :).
© Stack Overflow or respective owner