Need help with using regular expression in Java

Posted by richard on Stack Overflow See other posts from Stack Overflow or by richard
Published on 2010-05-21T00:50:33Z Indexed on 2010/05/21 1:10 UTC
Read the original article Hit count: 329

Filed under:
|

Hi,

I am trying to match pattern like '@(a-zA-Z0-9)+ " but not like 'abc@test'.

So this is what I tried:

Pattern MY_PATTERN
    = Pattern.compile("\\s@(\\w)+\\s?"); 
String data = "[email protected] #gogasig @jytaz @tibuage";
    Matcher m = MY_PATTERN.matcher(data);
StringBuffer sb = new StringBuffer();
boolean result = m.find(); 
while(result) {
    System.out.println (" group " + m.group());
    result = m.find();
}

But I can only see '@jytaz', but not @tibuage. How can I fix my problem? Thank you.

© Stack Overflow or respective owner

Related posts about java

Related posts about regex