admin管理员组文章数量:1357568
i need to figure out what this regular expression means?
"^[A-Z]{3}-[4-7]\d{2,4}\$$"
I think it starts with exactly 3 letters and ends with 2,3 or 4 digits (also not sure about the dubble $-sings) .
But I can't understand what this means:
-[4-7]
And I'm also not sure why there are 2 $ at the end ...
thanks
i need to figure out what this regular expression means?
"^[A-Z]{3}-[4-7]\d{2,4}\$$"
I think it starts with exactly 3 letters and ends with 2,3 or 4 digits (also not sure about the dubble $-sings) .
But I can't understand what this means:
-[4-7]
And I'm also not sure why there are 2 $ at the end ...
thanks
Share Improve this question asked Aug 19, 2013 at 15:31 nclsvhnclsvh 2,8686 gold badges34 silver badges53 bronze badges 1- This is basic regex syntax. Check out: regular-expressions.info. – ridgerunner Commented Aug 19, 2013 at 15:39
5 Answers
Reset to default 11^
the start of the string[A-Z]{3}
a character from A to Z repeated 3 times-
the character-
[4-7]
a digit from 4 to 7\d{2,4}
any digit from 0 to 9 repeated between 2 and 4 times\$
the character$
$
the end of the string
Regular Expressions 101
Go to regex101. and paste the regex in there...it will describe it to you. This will allow you to also test your regex within your browser.
give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime
REGEX
/"^[A-Z]{3}-[4-7]\d{2,4}\$$"/
Description
" Literal "
^ Start of string
Char class [A-Z] 3 times [greedy] matches:
A-Z A character range between Literal A and Literal Z
- Literal -
Char class [4-7] matches:
4-7 A character range between Literal 4 and Literal 7
\d 2 to 4 times [greedy] Digit [0-9]
\$ Literal $
$ End of string
" Literal "
Visualization (thanks to naomik) provided by debuggex
Visualize!
Also, that's not a Regular Expression (RegExp); that's just a string.
If you want to make it a RegExp:
var re = new RegExp("^[A-Z]{3}-[4-7]\\d{2,4}\\$$");
Or just
var re = /^[A-Z]{3}-[4-7]\d{2,4}\$$/;
-[4-7]
means the character -
followed by one of the characters 4
, 5
, 6
and 7
.
The first $
is escaped - so it indicates a $
in the input, whereas the second $
is not escaped, and so it indicates the end of the string.
-
: this is literally the minus -
character.
[4-7]
: a single digit, either 4,5,6 or 7.
\$
is just an escaped $
sign, so it's interpreted as text, and not as "end of string".
本文标签: javascriptWhat is the meaning of this regexpStack Overflow
版权声明:本文标题:javascript - What is the meaning of this regexp? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743979543a2571019.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论