0

I have seen a lot of useful links in this site about regular expression, I used it to create the following regular expression for the command but it won't work:

if(input.matches("find -[0-9]+ A www.(.*).(.*)")){
     System.out.println("m=" +input);
     }
 else{System.out.println("m=" +input);}

but it didn't work, what did I do wrong?

Note:

  • find -2 A www.google.com should be accepted
  • find -2 A www.facebook.com should be accepted
  • find -A A www.facebook.com shouldn't be accepted
  • find -2 B www.facebook.com shouldn't be accepted
2
  • 1
    What is not working? Better you use "^find -[0-9]+ A www\\.([^.]+)\\.(.+)$"
    – anubhava
    Nov 24, 2015 at 18:15
  • Have you tried your regex here ? You should try find -[0-9]+ A www.(.*) I think the format will suit you better. Example
    – naurel
    Nov 24, 2015 at 18:21

1 Answer 1

1

I think you forgot the to escape the middle dot.

find -[0-9]+ A www.(.*)\.(.*)

Should do what you want : test

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.