2

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 simply DEBUG[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 :).

1 Answer 1

2

try this, written in java, but you can transform it to python

replaceAll("(DEBUG[1-5]\s*\\(\")\"[^:]+:\\s+([^;]+)", "$1$2");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.