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/Regex: Replace all values starting with % and upto but not include comma or quote?

I have the following string:

test0,test1%something1,{"test2%something2","test3%something3", "test4"}

I want to write a regex(via Java String.replaceAll) to get rid of all text between %(including) and comma or quote(excluding) such that I end up with:

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

test0,test1,{"test2","test3", "test4"}

I have following regex:

(%.*?)[\,,\"]

But this is also capturing the comma or the quote so that I end up with:

test0,test1{"test2,"test3, "test4"}

How do I exclude the comma/quote?

>Solution :

Use this Regex:

%.*?(?=[,"])
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