admin管理员组文章数量:1415697
I am trying to get a regular expression to work but am stumped. What I want is to do the inverse of this:
/(\w)\1{5,}/
This regex does the exact opposite of what I'm trying to do. I would like to get everything but a string that has 6 repeating numbers i.e. 111111
or 999999
.
Is there a way to use a negative look-around or something with this regex?
I am trying to get a regular expression to work but am stumped. What I want is to do the inverse of this:
/(\w)\1{5,}/
This regex does the exact opposite of what I'm trying to do. I would like to get everything but a string that has 6 repeating numbers i.e. 111111
or 999999
.
Is there a way to use a negative look-around or something with this regex?
Share Improve this question edited Jun 10, 2015 at 22:56 Wiktor Stribiżew 628k41 gold badges498 silver badges616 bronze badges asked Jun 10, 2015 at 20:36 HaggardWolfHaggardWolf 235 bronze badges 3- Is a string with 7 repeating numbers OK? Also your regex doesn't make sense. Why is 1 escaped? Are you just that isn't a regex used in a substitution regex? – Martin Konecny Commented Jun 10, 2015 at 20:42
- What is the puting language or tool you are using? – Wiktor Stribiżew Commented Jun 10, 2015 at 21:39
- To be clear, I am using a jQuery plugin called validation engine. I am trying to add a custom regex to the language file. I am just starting to dig into regex and am very novice. The regex I pasted above was something I found online that seems to work on regexr. to find repeating numbers. And yeah, the user can only input 6 numbers so 7 repeating numbers is ok. – HaggardWolf Commented Jun 10, 2015 at 22:25
2 Answers
Reset to default 6You can use this rgex:
/^(?!.*?(\w)\1{5}).*$/gm
RegEx Demo
(?!.*?(\w)\1{5})
is a negative lookaahead that will fail the match if there are 6 consecutive same word characters in it.
I'd rather go with the \d
shorthand class for digits since \w
also allows letters and an underscore.
^(?!.*(\d)\1{5}).*$
Regex explanation:
^
- Start of string/line anchor(?!.*(\d)\1{5})
- The negative lookahead checking if after an optional number of characters (.*
) we have a digit ((\d)
) that is immediately followed with 5 identical digits (\1{5}
)..*
- Match 0 or more characters up to the$
- End of string/line.
See demo. This regex will allow
本文标签: javascriptRegex not matching 6 repeated numbersStack Overflow
版权声明:本文标题:javascript - Regex not matching 6 repeated numbers - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745234851a2648988.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论