Hey everyone, I am writing a small parser and I am dividing the input into tokens, my tokens are delimited from one another by a space. They can enter their data in the form token(token) or token (token) or token token(token) etc... in the case where they dont put a space before the ( symbol. I am attempting to insert a space before it. The way I have been trying this is as so:
input.replaceAll("(", " (");
When I do that I get a PatternSyntaxException. Is this normal? Is there another way to do this? Any help is appreciated guys!
You have to escape the ( character... "\(". However, since this is within a Java String, you must escape the \. Also, remember that Strings are immutable so you will want to set a String equal to the method.