2 Replies - 395 Views - Last Post: 19 July 2010 - 09:31 AM Rate Topic: -----

#1 paser  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 135
  • Joined: 30-May 09

Help with PatternSyntaxException

Posted 19 July 2010 - 09:19 AM

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!

Is This A Good Question/Topic? 0
  • +

Replies To: Help with PatternSyntaxException

#2 Ember  Icon User is offline

  • D.I.C Head

Reputation: 70
  • View blog
  • Posts: 160
  • Joined: 24-April 10

Re: Help with PatternSyntaxException

Posted 19 July 2010 - 09:30 AM

Don't quote me on this, but I think it has something to do with the regex input going wrong. Isn't "(" a meta-character in regex terms?
Was This Post Helpful? 1
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2871
  • View blog
  • Posts: 11,026
  • Joined: 15-July 08

Re: Help with PatternSyntaxException

Posted 19 July 2010 - 09:31 AM

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.

text = text.replaceAll("\\(", " \\(");


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1