This discussion is archived
2 Replies Latest reply: Nov 3, 2009 11:34 PM by 807580 RSS

Regex: Getting different groups with * operator

807580 Newbie
Currently Being Moderated
Hello!

How can I store the different hits in a string using operators ()* (real question mark ^_^')? I have
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class RegexTestHarness {

    public static void main(String[] args){
        
         
         String text = "Asian.lstas";
         String filename = null;
         Matcher matcher = Pattern.compile("(as)*").matcher(text);
         if (matcher.lookingAt())
         {
              System.out.println(matcher.groupCount());
            filename = matcher.group(1);
         }
         System.out.println(filename);
    }
}
The output is
1
null
where I expected
2
as
Can anyone explain please?