Tried this in many languages with same result.
JavaScript example:
/[A-z]/.test("_"); // => true
/[A-z]/.test("0"); // => false
/[A-z]/.test("-"); // => false
/[A-z]/.test("A"); // => true
Why is the first case not returing false
?
The _ (underscore) character in the regular expression means that the zone name must have an underscore immediately following the alphanumeric string matched by the preceding brackets. The . (period) matches any character (a wildcard).
regex allows only for the special character UNDERSCORE, SPACE, SINGLE QUOTE and HYPHEN.
The range A-z is valid, but you should note that this includes non-letter characters like ^ and [ . 0-Z is also valid and includes : , ? , and a whole bunch of other characters you probably don't want. To answer your question, you can create any range in the right order.
The regular expression [A-Z][a-z]* matches any sequence of letters that starts with an uppercase letter and is followed by zero or more lowercase letters. The special character * after the closing square bracket specifies to match zero or more occurrences of the character set.
Character ranges are not that intelligent. They are based on ascii codes. Check out Ascii Table. There exist special characters between upper-case A-Z
and lower-case a-z
range, namely:
[
\
]
^
_
`
So, instead of A-z
it should be A-Za-z
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With