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

前端 未结 7 1448
伪装坚强ぢ
伪装坚强ぢ 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:18

    I've just fallen over this in a script (not my own).

    It seems that grep, awk, sed accept [a-Z] based on your locale (i.e. LANG or LC_CTYPE environment variable). In POSIX, [a-Z] isn't allowed by these tools, but in some other locales (e.g. en_gb.utf8) it works, and is the same as [a-zA-Z].

    Yes, I've checked, it doesn't match any of _^[]`.

    Given that this has taken quite some time to debug, I strongly discourage anyone from ever using [a-Z] in a regex.

提交回复
热议问题