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

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

问题描述

我正在使用正则表达式为一个文本框编写输入验证器,我只想要字母字符。我想知道 [Az] [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] ,并且没有提及 [Az]

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

我正在使用java的 String.matches(正则表达式)

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

推荐答案

[Az] 将匹配范围内的ASCII字符从 A z ,而 [a-zA-Z] 将匹配范围从 A Z 范围内的ASCII字符从 a z 。乍一看,这似乎相当 - 但是,如果你看一下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天全站免登陆