I am testing for a string if it contains at least n chars in consecutive order:
I have this regex but it doesn’t seems to work
(\w\1){3,}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
(\w)\1{3,}This makes sure that you have a character repeating at least four times.The problem with
(\w\1)is that the backreference\1is inside the capturing group itself.\1refers to the character(s) matched by the first parenthetical()group.If you want to capture the whole matched string, enclose the regex in another parenthetical group.
Note that here the index of backreference is
\2as\1refers to the outer parentheses.Check the example: