PDA

View Full Version : Java Regular Expressions


DBQ
April 12th, 2008, 03:18 PM
Hi everybody.

Simple question about java regular expressions. Using the Pattern and Matcher classes.

Suppose my text contains characters such as "( )" . However, these are special characters used for capturing strings. Suppose I want to get the tokens inside the if statement "if(x==y)" do I specify the parenthesis as regular characters using "\(\)"? -- like in Perl?

nick_h
April 12th, 2008, 06:12 PM
Have a look at the "Backslashes, escapes, and quoting" section in this (http://java.sun.com/j2se/1.5.0/docs/api/java/util/regex/Pattern.html) link.

Use \\( and \\)