I am trying to match string which,
-
should contain at least one character which is not a space
-
the string should be 1 to 8 characters in length,
I wonder why the below code is not working when i want to restrict to 1 to 8 characters.
.*\S.{1,8}
should match,
abcdefge
abcdefg - first character is space, Any number of spaces can be there, but atleaset one non space character should be there
a
Should not match,
- All spaces
abcdefghijklm - Exeeds more then 8 characters
Thanks
use a look-ahead for your first criteria, and a quantified ‘anything’ character combined with start and end anchors for the second:
(this isn’t tested so my apologies for the bugs)