I am looking for a regex where i have one or more words (possibly should cover alpha numeric also) separated by spaces (one or more spaces)
Above are some examples of it
I wrote a regex to see what is repeating for #1
\s*[a-zA-Z]*\s*[a-zA-Z]*\s*[a-zA-Z]*\s*
so i wanted to do something like {3}
for repeating section.
But it does not seem to work.. I cant believe it is this difficult.
(\s*[a-zA-Z]*){3}
$ means "Match the end of the string" (the position after the last character in the string).
Yes, also your regex will match if there are just spaces. My reply was to Neha choudary's comment. @Pierre Three years later -- I came across this question today, saw your comment; I use regex hero (regexhero.net) for testing regular expressions.
The most common forms of whitespace you will use with regular expressions are the space (␣), the tab (\t), the new line (\n) and the carriage return (\r) (useful in Windows environments), and these special characters match each of their respective whitespaces.
\d (digit) matches any single digit (same as [0-9] ). The uppercase counterpart \D (non-digit) matches any single character that is not a digit (same as [^0-9] ). \s (space) matches any single whitespace (same as [ \t\n\r\f] , blank, tab, newline, carriage-return and form-feed).
If you do not care just how many words you have, this would work:
[\w\s]+
\w
is any alphanumeric. Replace it with a-zA-Z
if you need only letters.
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