gpt4 book ai didi

regex - 正则表达式范围 a-Z 中将包含哪些字符?

转载 作者:行者123 更新时间:2023-12-04 18:08:57 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





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

(7 个回答)


2年前关闭。




如果我有一个正则表达式 [0-Z][a-Z] - 它会匹配哪些字符?它是有效的正则表达式吗?您可以在 0-9 之外的正则表达式中设置范围吗? , a-zA-Z ?

最佳答案

是的,您可以有其他范围。来自 MSDN - Character Classes in Regular Expressions(粗体是我的):

The syntax for specifying a range of characters is as follows:


[firstCharacter-lastCharacter]

where firstCharacter is the character that begins the range and lastCharacter is the character that ends the range. A character range is a contiguous series of characters defined by specifying the first character in the series, a hyphen (-), and then the last character in the series. Two characters are contiguous if they have adjacent Unicode code points.



因此,最终 [0-Z] 将匹配 0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ 。您可以检查 ASCII table0-Z

至于 [a-Z] ,因为它们没有指定连续的系列,所以它们应该不匹配。

请记住,对于一般规则,效果可能是广泛的:Unicode 字符代码,而不仅仅是 ASCII - 当然,最终取决于实现,因此,如果有疑问,请检查它。

关于regex - 正则表达式范围 a-Z 中将包含哪些字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19409727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com