1)How to say in regular expression: increase match counter only if there are no letters at all?
I came up with this:
"/^[^a-zA-Z]+$/"
and it seems to work, but I don’t get why "/^[^a-zA-Z]+/" doesn’t work while "/[^a-zA-Z]+$/" works?
2)What does this mean?: "/[a-zA-Z]+/" I thought it means that match counter will increase only if all the elements will be in range a-z or A-Z. But testing shows I’m wrong. Also tried this "/^[a-zA-Z][a-zA-Z]+/" but this also give 1 for “aa11”.
Thanks in advance
The only correct regular expression you’ve posted is
/^[^a-zA-Z]+$/. All the rest are wrong.You need the
^and$to anchor the match to the start and end of the string respectively./^[^a-zA-Z]+/matchesaaa111because there’s no end-of-string anchor./[^a-zA-Z]+$/matches111aaabecause there’s no start-of-string anchor./[a-zA-Z]+/matches111aaa111because there’s no start- or end-of-string anchor. It matches if there’s any letter anywhere in the string.