本文介绍了为什么匹配 1 到 10 的正则表达式写为 [1-9]|10 而不是 [1-10]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么匹配 1 到 10 数字的正则表达式通常写成这样?
Why is the regex to match numbers from 1 to 10 commonly written as follows?
[1-9]|10代替:
[1-10]或者这个:
[1-(10)] 推荐答案有时候一幅价值 1000 字的好画...
以下是您问题中的三个命题以及正则表达式理解它们的方式:
Here are the three propositions in your question and the way a regex flavour would understand them:
Invalid regexp !!此正则表达式无效,因为范围以一个数字开头 (1-) 但未以另一个数字结尾(以 ( 结尾).
This regex is invalid because a range is opened (1-) with a digit but not closed with another digit (ends with ().
一个范围通常用两边的数字或两边的字母来绑定.
A range is usually bound with digits on both sides or letters on both sides.
使用 Debuggex
更多推荐
为什么匹配 1 到 10 的正则表达式写为 [1
发布评论