Link to home
Start Free TrialLog in
Avatar of birdiestremph
birdiestremph

asked on

weird java regex stuff

CODE:
  System.out.println("4.5.2".matches("([0-9]*(\\.)*)*"));
          
          System.out.println(("mozilla 4.5.2".split("([0-9]*(\\.)*)*"))[1]);
          
            Pattern p = Pattern.compile("([0-9]*(\\.)*)*");
            Matcher m = p.matcher("mozilla 4.5.2");
            boolean ffVersion  = m.find();

              if(ffVersion)
              {
                    System.out.println(m.start(0));
                    System.out.println(m.end(0));
              }
OUTPUT:

true
m
0
0


So ... it is matching the pattern when i use match(), however the split is splitting as if its delimeter is "", and the matcher isnt finding the pattern at all ...  

Any suggestions?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of birdiestremph
birdiestremph

ASKER

Thanks!  

that wasn't quite what i needed, but using the plus made my realize that by putting a * after everything i do is going to match anything. This is what i used instead -  "([0-9]+\\.*)+"


:-)

Your pattern will of course match "1234567890" but maybe that's no bad thing ...