Replace blank spaces and semicolon in Java with Regex

xmlParser :

I am trying to replace all strings that can contain any number of blank spaces followed by an ending ";", with just a ";" but I am confused because of the multiple blank spaces.

"ExampleString1            ;" -> "ExampleString1;"
"ExampleString2  ;" -> "ExampleString2;"
"ExampleString3     ;" -> "ExampleString3;"
"ExampleString1 ; ExampleString1 ;" -----> ExampleString1;ExampleString1

I have tried like this: example.replaceAll("\\s+",";") but the problem is that there can be multiple blank spaces and that confuses me

Bambus :

Try with this:

replaceAll("\\s+;", ";").replaceAll(";\\s+", ";")

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=97587&siteId=1