admin管理员组文章数量:1287858
I have small requirement.I want to search a string with exact match. Suppose i want to search for None_1, i am searching for 'None_1' using /None_1/, but it is matching even "xxxNone" but my requirement is it should match only None_[any digit]. Here is my code
/^None_+[0-9]{?}/
So it should match only None_1 , None_2
I have small requirement.I want to search a string with exact match. Suppose i want to search for None_1, i am searching for 'None_1' using /None_1/, but it is matching even "xxxNone" but my requirement is it should match only None_[any digit]. Here is my code
/^None_+[0-9]{?}/
So it should match only None_1 , None_2
Share Improve this question asked Jun 27, 2011 at 9:03 ReddyReddy 1,3853 gold badges23 silver badges45 bronze badges2 Answers
Reset to default 8You should also anchor the expression at the end of the line. But that alone will not make it work. Your expression is wrong. I think it should be:
/^None_[0-9]+$/
^
matches the beginning of a line[0-9]+
matches one or more digitsNone_
matchesNone_
$
matches the end of a line
If you only want to match one digit, remove the +
.
Your original expression /^None_+[0-9]{?}/
worked like this:
^
matches the beginning of a lineNone
matchesNone
_+
matches one or more underscores[0-9]
matches one digit{?
matches an optional opening bracket{
}
matches}
Try this:
/^None_+[0-9]{?}$/
本文标签: javascriptHow to match with an exact string using regular expressionStack Overflow
版权声明:本文标题:javascript - How to match with an exact string using regular expression - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741325423a2372449.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论