正则表达式 [a-Z] 是否有效,如果是,那么它是否与 [a-zA-Z] 相同? [英] Is the regular expression [a-Z] valid and if yes then is it the same as [a-zA-Z]?

查看:24
本文介绍了正则表达式 [a-Z] 是否有效,如果是,那么它是否与 [a-zA-Z] 相同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正则表达式 [a-Z] 是否有效,如果是,那么它是否与 [a-zA-Z] 相同?请注意,在 [a-Z] 中,a 是小写字母,而 Z 是大写字母.

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.

我收到了一些答案,指出虽然 [a-Z] 无效,但 [A-z] 有效(但不会与 [a-zA-Z] 相同),这正是我想要的.因为我想知道是否可以用更紧凑的版本替换 [a-zA-Z].

I received some answers specifiying that while [a-Z] is not valid then [A-z] is valid (but won't be the same as [a-zA-Z]) and this is really what I was looking for. Since I wanted to know in general if it's possible to replace [a-zA-Z] with a more compact version.

感谢所有为答案做出贡献的人.

Thanks for all who contributed to the answer.

推荐答案

否,a (97) 高于 Z (90).[a-Z] 不是有效的字符类.然而 [A-z] 也不是等价的,但出于不同的原因.它会覆盖所有字母,但也会包括大写和小写字母之间的字符:[\]^_`.

No, a (97) is higher than Z (90). [a-Z] isn't a valid character class. However [A-z] wouldn't be equivalent either, but for a different reason. It would cover all the letters but would also include the characters between the uppercase and lowercase letters: [\]^_`.

这篇关于正则表达式 [a-Z] 是否有效,如果是,那么它是否与 [a-zA-Z] 相同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆