I want to determine whether a string consists of only two words, with one space character between them. The first word should only include alphanumeric characters. The second should include only numbers. An example is: asd 15
I would like to use String.matches. How can I do this or which regex should I use?
Thanks in advance.
You look for something like:
String regex = "^[A-Za-z]+ [0-9]+$";
Explanation:
^ the beginning of the string (nothing before the next token)
[A-Za-z]+ at least one, but maybe more alphabetic chars (case insensitive)
a single space (hard to see :) )
[0-9]+ at least one, but maybe more digits
$ end of the string (nothing after the digits)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With