Regular Expression for escaping periods
807603Jan 31 2008 — edited Jan 31 2008Hi,
I'm trying to use the RegEx method of the String class to match a value. The trouble is the String value I'm trying to match are periods, which are as you know the predefined "any" character for matching. http://java.sun.com/j2se/1.4.2/docs/api/java/util/regex/Pattern.html
How do I successfully escape this so it will hunt for a period? I assumed I could escape it with the backslash \. but my compiler shows an error as: "Illegal escape character in String literal".
Take for example:
// sample string is a bad email address with 2 periods.
String = email_address = johndoe@sun..com;
boolean is_bad_email_email = email_address.matches("\.\.");
When I test the RegEx it works stand alone, but why won't it let me escape the period in the above example? Is there another way to do this?
Thanks!