Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

help needed to understand why my regex is working !!!

  •  07-24-2009, 6:15 AM

    help needed to understand why my regex is working !!!

    hello all

    i am playing with one regular expression using Java programming language (JDK 1.6) and i am unable to understand how (rather why!) it works.

    here is my code
    String text = "I am also known as John,PP)";
    String pattern = "John([\\s\\u00A0)\\}\\]\"'-/\\\\.:;!'$?]|$)";
     
    Matcher matcher = Pattern.compile(pattern,
    Pattern.UNICODE_CASE | Pattern.CASE_INSENSITIVE).matcher(text);
    while (matcher.find())
    {
    String foundString = matcher.group();
    System.out.println(foundString);
    }
    above code when executed prints "John,"
    what i am unable to understand is ... though the pattern does not have any comma (,) why the string "John," is getting matched ???

    any help would be really appreciated ....

    thanks
    ~PP
View Complete Thread