javascript - Matching strings with underscores, lowercase ASCII letters, ASCII digits, hyphens or dots only not starting with dot and hyphen -
i need regular expression match string that
_test 123test test test_123 test-123 123.a
i created regular expression:
/^[_0-9a-z][_.\-a-z0-9]*$/
however, want exclude string if contains numbers.
how can fix it?
to avoid matching digit-only string, add negative lookahead:
^(?![0-9]+$)[_0-9a-z][_.\-a-z0-9]*$ ^^^^^^^^^^
the (?![0-9]+$)
lookahead triggered once @ beginning of string , try match 1 or more digits end of string. if found, match failed (no match returned) lookahead negative.
Comments
Post a Comment