Regex from a to z
Will this Regex syntax check for the 1st letter starting from a range of "a to z"?
开发者_如何学JAVA(/^[a-zA-Z].*/i.test(mystring))
Yes. It can be further simplified to /^[a-z]/i
.
Breakdown:
^
= start of the string[a-z]
= any letter in the range from a to z- the
i
at the end = case isensitive, means that[a-z]
will also match in the range of A to Z.
For more info, check out this quickstart guide.
Yes, and you don't really even need the ".*".
You don't need the ".*" because ".*" essentially says match every character(.), zero or more times(*). Since you only want to match one character, all you need is the ^[a-zA-Z], which makes sure the first letter is a-zA-Z.
Also to simplify this regex to:
/^[a-z]/i
because this makes the regex case in-sensitive.
Yes it surely will do that and /^[a-z]/i would do it too
精彩评论