Regex for Consecutive Identical Characters or Numbers
# Regex for checking three or more consecutive identical characters or numbers
To check for three or more consecutive identical characters or numbers, you can use the following regular expression:
### A possible regex
“`
(.)\1{2,}
“`
### Regex Breakdown
“`
(.) # Matches any character and captures it in a group
\1{2,} # Matches the captured character (referred to as \1) two or more times
“`
This regular expression uses a capturing group to match any character and then checks if the same character repeats two or more times consecutively.
Examples of strings that should match this regular expression are:
– `aaa`
– `1111`
– `bbbbb`
Examples of strings that should not match this regular expression are:
– `abab`
– `12345`
– `xyz`
### Final notes
Note that this regular expression will only check for consecutive identical characters or numbers. If you want to check for consecutive identical characters or numbers within a larger string, you may need to modify the regular expression accordingly.
Read more here: Source link
