Last active
July 30, 2018 20:13
-
-
Save moiseshilario/3818a12048a05912add7bef07b0cb0f8 to your computer and use it in GitHub Desktop.
Repeated number regex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regex to get any repeated numbers in a string | |
var repeatedNumber = /(\d)\d*\1/ | |
/* | |
(\d) -> first group (a number in this case) that will be checked by \1 | |
\d* -> any quantity of digits between the number to be checked and the "checker" | |
\1 -> same stuff that is in the 1st group (in this case, a digit = \d) | |
e.g | |
00: | |
- (\d) = 0 (first group) | |
- \d* = nothing (empty space) | |
- \1 = checks that the second '0' matches the first group ('0') | |
9239: | |
- (\d) = 9 (first group) | |
- \d* = 23 | |
- \1 = the second 9 | |
0434: | |
- (\d) = 4 (first group) | |
- \d* = 3 | |
- \1 = the second 4 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment