Is the regular expression [a-Z] valid and if yes then is it the same as [a-zA-Z]?

前端 未结 7 1551
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 07:53

Is the regular expression [a-Z] valid and if yes then is it the same as [a-zA-Z]? Please note that in [a-Z] the a is lowercase and the Z is uppercase.

E

7条回答
  •  生来不讨喜
    2020-11-27 08:23

    If it's valid, it won't do what you expect.

    The character code of Z is lower than the character code of a, so if the codes are swapped to mean the range [Z-a], it will be the same as [Z\[\\\]^_`a], i.e. it will include the characters Z and a, and the characters between.

    If you use [A-z] to get all upper and lower case characters, that is still not the same as [A-Za-z], it's the same as [A-Z\[\\\]^_`a-z].

提交回复
热议问题