I’m writing a password strength checker in PHP, and I’m using Regular Expressions to calculate various parameters for the strength calculation. I need to be able to check the number of repeating consecutive characters in a string. For example:
baaabaaablacksheep would return 5
sillystring would return 1
and so on...
You can use regex with
\1+to find the repeating characters, and then usestrlen()to count them. Try something like:Output: