正则表达式 [A-z] 和 [a-zA-Z] 之间的区别 [英] Difference between regex [A-z] and [a-zA-Z]

查看:39
本文介绍了正则表达式 [A-z] 和 [a-zA-Z] 之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用正则表达式为我只需要字母字符的文本框编写输入验证器.我想知道 [A-z][a-zA-Z] 是否等效,或者在性能方面是否存在差异.

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] were equivalent or if there were differences performance wise.

我一直在搜索[a-zA-Z],但没有提到[A-z].

I keep reading [a-zA-Z] on my searches and no mention of [A-z].

我正在使用 java 的 String.matches(regex).

I am using java's String.matches(regex).

推荐答案

[Az] 将匹配 Az 范围内的 ASCII 字符code>,而 [a-zA-Z] 将匹配 AZ 范围内的 ASCII 字符> 范围从 az.乍一看,这似乎是等效的——但是,如果您查看此表 ASCII 字符,您会将看到 Az 包含几个其他字符.具体来说,它们是[]^_`(您显然不想要).

[A-z] will match ASCII characters in the range from A to z, while [a-zA-Z] will match ASCII characters in the range from A to Z and in the range from a to z. At first glance, this might seem equivalent -- however, if you look at this table of ASCII characters, you'll see that A-z includes several other characters. Specifically, they are [, , ], ^, _, and ` (which you clearly don't want).

这篇关于正则表达式 [A-z] 和 [a-zA-Z] 之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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