为什么匹配 1 到 10 的正则表达式写为 [1

编程入门 行业动态 更新时间:2024-10-23 22:34:22
本文介绍了为什么匹配 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

本文发布于:2023-06-08 21:26:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/589342.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!