iqueqiorio iqueqiorio - 2 months ago 7
Java Question

remove all spaces regrex

I am trying to remove everything inside the "( )" and all spaces in java with regrex I am close here is the string

First Last "(Some stuff)"


And here is my regrex

\s\"\([^)]*\)\"


the only thing it doesnt do it remove the space between first and last?

How can I add that?

Answer

You can use altenration to match text inside (..) or spaces:

str = str.replaceAll("\"\\([^)]*\\)\"|\\s+", "");

RegEx Demo

Comments