I have searched for a regex that check for long words in a text string. The text sting can be long, but any words in this string should not be longer than 20 characters. I have tried a lot of different expressions, but all gives me the exeption even if no word is longer thean 20 chars (the total text is longer than 20 chars). I am using asp.net c#. Please see attached code.
I Have tried these expressions without luck:ValidationExpression="^\S{20}$"ValidationExpression="^\w{20}$"ValidationExpression="^\w{20,}$"ValidationExpression="^\b\w{20,}$"ValidationExpression="^\b\p{L}{20,}$"ValidationExpression="^\w{0,20}$"
Nope, this also return expeption even if the text is "hello world hello world hello world hello world". It takes the entire string, not each word in the sting. :)
evilrix
>> It takes the entire string, not each word in the sting
It should stop matching at the space because \w matches words (A-Z, a-z and _) and doesn't match space. This being the case it should not be matching the whole string only the first word of that string. I tested it with RegexBuddy and what I expected to happen is what happens.
\b Matches at the position between a word character (anything matched by \w) and a non-word character (anything matched by [^\w] or \W) as well as at the start and/or end of the string if the first and/or last characters in the string are word characters.
\b\w{0,20}\b