1

I have around 200 function calls of the form

markers.add(packageDecl.getPosition(), "package.invalid", this.fullName);

which need to be replaced with

markers.add(I18n.createMarker(packageDecl.getPosition(), "package.invalid", this.fullName));
            ^^^^^^^^^^^^^^^^^^                                                            ^

They can have an arbitrary number of function arguments and the arguments can be nested calls, as seen in the example. However, it is given that the ; is always succeeded by a newline.


I already tried this regex:

markers\.add\((.*)$

Which allows me to strip the markers.add( part and add the I18n.createMarker(. However, I cannot add the extra closing parenthesis at the end: ); -> ));.

2 Answers 2

1

Can you not use this:

Regex:   markers\.add\((.*)\)"
Replace: markers.add(I18n.createMarker(\1))
Sign up to request clarification or add additional context in comments.

Comments

0

This ugly thing seems to work with Eclipse regex find :

markers\.add\((.|\n)*;$

4 Comments

You should look up DOTALL mode in the Java regex docs. There's no need for hacks like (.|\n).
@AlanMoore I know about regex flags but I don't think the regex search/replace that Clashsoft mentionned in a comment supports them. Am I mistaken?
The question is tagged java, so I assumed it was for Java code and he was only using Eclipse for testing. But no matter, Eclipse itself uses the ICU library, which has almost exactly the same syntax and semantics as the Java flavor (a deliberate design choice). Oh, and there's another problem with (.|\n). There are several other line separator characters that . doesn't match, so technically, you should have been using. (.|[\r\n\u0085\u2028\u2029]). If you were going that route. Which you shouldn't.
@AlanMoore It turned out I had forgotten about flags shorthands in Java so thank you for insisting !

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.