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

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -