正则表达式末尾大括号中逗号分隔的数字是什么意思? [英] What do comma separated numbers in curly braces at the end of a regex mean?
问题描述
我试图理解以下正则表达式,我理解最初的部分,但我无法弄清楚 {3,19} 在这里做什么:
I am trying to understand the following regex, I understand the initial part but I'm not able to figure out what {3,19} is doing here:
/[A-Z][A-Za-z0-9\s]{3,19}$/
推荐答案
这就是称为量词的自定义重复操作.
That is the custom repetition operation known as the Quantifier.
\d{3}
将正好找到三位数字.
\d{3}
will find exactly three digits.
[a-c]{1,3}
将查找 a、b 或 c 至少出现一次,但最多出现 3 次.
[a-c]{1,3}
will find any occurrance of a, b, or c at least one time, but up to three times.
\w{0,1}
表示可以选择找到一个单词字符.这与放置问号相同,例如:\w?
\w{0,1}
means a word character will be optionally found. This is the same as placing a Question Mark, e.g.: \w?
(\d\w){1,}
将找到一个数字后跟一个单词字符的任意组合至少一次,但最多无限次.所以它会匹配 1k1k2k4k1k5j2j9k4h1k5k
这与加号相同,例如:(\d\w)+
(\d\w){1,}
will find any combination of a Digit followed by a Word Character at least One time, but up to infinite times. So it would match 1k1k2k4k1k5j2j9k4h1k5k
This is the same as a Plus symbol, e.g.: (\d\w)+
b{0,}\d
将可选地找到字母 b
后跟一个数字,但也可以匹配无限字母 b
's 后跟一个数字.所以它会匹配5
、b5
,甚至bbbbbb5
.这与星号相同.例如:b*\d
b{0,}\d
will optionally find the letter b
followed by a digit, but could also match infinite letter b
's followed by a digit. So it will match 5
, b5
, or even bbbbbbb5
. This is the same as an Asterisk. e.g.: b*\d
这篇关于正则表达式末尾大括号中逗号分隔的数字是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!