开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜