2 Replies Latest reply: Nov 4, 2009 1:34 AM by 807580 RSS

    Regex: Getting different groups with * operator

    807580
      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?