I am building a regex against strings that meet the following requirements:
For example, we can have "asa22d asdcac3" or "Asdcd234 sacasW2 sas1 s sd1" (hopefully you get the picture). So far I have:
^[A-z 0-9]\s{0,1}
I am not using \w because it allows underscores. This works for one set of characters, but I need to allow five sets of the same sort of strings separated by a space.
How can I do that?
You haven't said what language you are using, but this should do it for you:
^[A-Za-z0-9]+(\s[A-Za-z0-9]+){0,4}$
A word, followed by up to four instances of space-then-word.
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