Tuesday, March 15, 2011

Regex Pattern Matcher

Java provides a vety cool way to use java regex .... !!

Here is the small example of the regex, code snippet goes here ...

        String hostConnector = "6xyz";
        String regex = "(\\d+)(\\w+)";
       
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(hostConnector);
        if (m.matches())
        {
            System.out.println("Tokens are: ");
            for (int i = 1; i <= m.groupCount(); i++)
            {
                System.out.print(" Next: "+m.group(i));
            }
        }

No comments:

Post a Comment