I tried many variants of different solutions explained here
How to add space on both sides of a string in Java
Regex add space between all punctuation
Add space after capital letter
As well as other ones regarding parenthesis (and many more)
I have a String and I simply want this : hi()
To become this : hi ( )
What I have tried so far :
if (phrase.matches("^.*[(].*$")){
phrase.replaceAll("\\(", " \\( ");
}
The if works fine but the replaceAll doesn't do anything.
I read online that I might need to put the previous values in the replaceAll so I tried the following
if (phrase.matches("^.*[(].*$")){
phrase.replaceAll("(.*)\\(", " \\( ");
}
As well as this
if (phrase.matches("^.*[(].*$")){
phrase.replaceAll("(.*)\\(", "(.*) \\( ");
}
And this
if (phrase.matches("^.*[(].*$")){
phrase.replaceAll("(.*)\\((.*)", "(.*) \\( (.*)");
}
At this point I feel that I am just trying random stuff and I'm missing something trivial here.