Basically, what I want to achieve is to not allow passwords with lots of consecutively repeated chars/digits. I'm trying to write a go function to which I pass a string and a maximum allowed number of consecutively repeated characters, and it should tell me if it's surpassed or not.
I used to do it easily in javascript using the a regular expression in the following way:
var regexString = '(.)\\1{' + (maxAllowedRepetitions) + ',}';
var regex = new RegExp(regexString);
return regex.test(string)
... where maxAllowedRepetitions is the max limit. If the limit is 3 and a string is 'blablabla', it returns false
. If it is blablaaaabla, it returns true
since the character 'a' is repeated more than 3 times.
I'm finding it difficult to achieve the same thing using go regexp.
I don't mind not using regexp. I just need a good way to achieve this.
Any suggestions?