My Java regex isn't capturing the group

Posted by Geo on Stack Overflow See other posts from Stack Overflow or by Geo
Published on 2010-03-11T21:39:12Z Indexed on 2010/03/11 21:49 UTC
Read the original article Hit count: 149

Filed under:
|

I'm trying to match the username with a regex. Please don't suggest a split.

USERNAME=geo

Here's my code:

    String input = "USERNAME=geo";
    Pattern pat = Pattern.compile("USERNAME=(\\w+)");
    Matcher mat = pat.matcher(input);
    if(mat.find()) {
        System.out.println(mat.group());
    }

why doesn't it find geo in the group? I noticed that if I use the .group(1), it finds the username. However the group method contains USERNAME=geo. Why?

© Stack Overflow or respective owner

Related posts about java

Related posts about regex