iqueqiorio iqueqiorio - 1 year ago 140
Java Question

Regular expression to remove all spaces

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


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

How can I add that?

Answer Source

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

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

RegEx Demo

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download