Difference between regex [A-z] and [a-zA-Z]

后端 未结 6 1962
北海茫月
北海茫月 2020-11-22 08:39

I am using a regex to program an input validator for a text box where I only want alphabetical characters. I was wondering if [A-z] and [a-zA-Z] we

6条回答
  •  感动是毒
    2020-11-22 09:31

    The square brackets create a character class and the hyphen is a shorthand for adding every character between the two provided characters. i.e. [A-F] can be written [ABCDEF].

    The character class [A-z] will match every character between those characters, which in ASCII includes some other characters such as '[', '\' and ']'.

    An alternative to specifying both cases would be to set the regular expression to be case-insensitive, by using the /i modifier.

提交回复
热议问题