RegEx to allow 9 numbers but block any more than 4 duplicate numbers

regex repeat pattern n times
regex 0 or 1 times
regex zero or more
regex repeat group
regex repeating pattern
regex match pattern multiple times
regular expression match
regex repeat character n times

I am looking for assistance with finding a RegEx to require exactly 9 numbers but block any more than 4 duplicate numbers in a row. If more or less than 9 characters are entered it should fail.

Examples would be:

  • 123456789 - allowed
  • 111156789 - allowed
  • 121314151 - allowed
  • 111116789 - not allowed
  • 123499999 - not allowed

I've tried the following with no luck:

/^(?!.*(\d)\1{5})(\d{9})*$/

Block any digit, that repeats 5 times in row: /^(?:(\d)(?!\1{4})){9}$/

Explanation:

(\d) - first group, that matches any digit. \1 - repeats first group contents. (\d)(?!\1{4}) - block digit, that have 4 same digits after it. (?:(\d)(?!\1{4})){9} - match only 9 of this patterns (each contain only one digit)

Example:

let reg = /^(?:(\d)(?!\1{4})){9}$/;

console.log(reg.test("123456789"));  // -> true
console.log(reg.test("111116789"));  // -> false
console.log(reg.test("12345678"));   // -> false
console.log(reg.test("1234567890")); // -> false

Regex Tutorial, RegexBuddy—Better than a regular expression tutorial! The asterisk or star tells the engine to attempt to match the preceding token zero or more times. The plus tells If the comma is present but max is omitted, the maximum number of matches is infinite. \b[1-9][0-9]{2,4}\b matches a number between 100 and 99999. The regex [0-9] matches single-digit numbers 0 to 9. [1-9] [0-9] matches double-digit numbers 10 to 99. That’s the easy part. Matching the three-digit numbers is a little more complicated, since we need to exclude numbers 256 through 999. 1 [0-9] [0-9] takes care of 100 to 199. 2 [0-4] [0-9] matches 200 through 249.


/(?=(?!(\d)\1{4}))^\d{9}$/

Explanation:

(\d)\1{4} - 5 repeating digits of the same number

(?!(\d)\1{4}) - Don't match 5 of the same number

(?=(?!(\d)\1{4})) - Make sure the expression doesn't include 5 digits of the same number, then return to the original starting point for further matching

^\d{9}$ - Match an expression that is 9 digits total

Regular Expression (Regex) Tutorial, OR Operator (|): E.g., the regex four|4 accepts strings "four" or "4" . Position Anchors: does not match character, but position such as start-of-line, end-of-line, 1.2 Example: Numbers [0-9]+ or \d+ This regex matches any numeric substring (of digits 0 to 9) of the input. For There are more than one ways to write a regex! Then, your regex will almost work. Currently, this matches any string that contains a sequence of 4 digits anywhere in the string. If you want to match only strings that contain EXACTLY 4 digits, you'll need to add the ^ (start of string) and $ (end of string) characters. So the full expression would be: regex(., '^[0-9]{4}$') Happy matching!


[PDF] Regular Expressions: The Complete Tutorial, Testing The Same Part of a String for More Than One Requirement . Matching Floating Point Numbers with a Regular Expression . Deleting Duplicate Lines From a File . 9. MySQL Regular Expressions with The REGEXP Operator. This tutorial is quite unique because it not only explains the regex syntax, but also  Yesterday, one of my colleagues needed a regex for filtering on Google Analytics. The value needed to be greater than 1200 to be valid. In case you are looking for a regex for something similar, I though I would post it so you can alter it for your needs. Regex greater than 1200 ^[1-9][2-9](?!00$)[0-9][1-9]?\d+$ I used this tool to test it.


Searching with Regular Expressions (RegEx), Metacharacters are the building blocks of regular expressions. For You can use regular expressions to search for social security numbers, patent numbers, [0-9]. Character set, at least one of which must be a match, but no more than one Textual near duplicate identification · Language identification · Email threading​  regular-expression I want the regular exp which accept only numbers 0-9 without any special character or decimal.Also single 0 should not be allowed but 0 followed with other numbers are allow. Posted 30-Jan-13 19:40pm


Searching with Regular Expressions, Metacharacters are the building blocks of regular expressions. Regular expressions can be used to search for social security numbers, patent numbers, URLs, email [0-9]. Character set, at least one of which must be a match, but no more than one unless otherwise specified. Textual near duplicate identification results. Right now, I’m trying to expand this to allow both 1 and 2-digit numbers that also begins and ends with a number. So numbers like “3”, “7”, “12” and “45”.


Regex remove duplicate characters, Regular Expression to This will remove duplicates and only one the It seems to remove the commas (my delimiter) in all but the first set. while we just want a character [Optional] The number of characters from the start {2,} then looks for more than 2 instances of that phrase in the string to match. [^a-zA-Z0-9] Ranges. Let’s say we have a string like +7(903)-123-45-67 and want to find all numbers in it. But unlike before, we are interested not in single digits, but full numbers: 7, 903, 123, 45, 67. A number is a sequence of 1 or more digits \d. To mark how many we need, we can append a quantifier. Quantity {n}