Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Java in notepad ++ – search first occurence of a pattern

I’m trying to capture all the output my code generates in the format "System.out.println(" until the first occurrence of ");" with the "Search regex patterns with notepad++" mode and replace it with "".
I have tested the following regex code:

System.out.println\(.*\);

So it works in a majority of cases but it’s a fragile regex because as soon as there is something like this further in the code on the same line:

System.out.println("sdsadas"); int blabla=1; Tony();

Then it takes all the text of that line until ); of tony and also deletes variables and functions.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Any idea how to be shure to capture the first occurence of ); ?

Thanks

PS: The issue has already been addressed here, but i didn’t find it earlier :), Maybe because my question was more specifically about notpad++ than REGEX in general.

>Solution :

You should make the dot in your regex pattern lazy/non greedy:

System\.out\.println\(.*?\);

Demo

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading