How to match any character which repeats n times?
Example:
for input: abcdbcdcdd
for n=1: ..........
for n=2: .........
for n=3:
With .NET regular expressions you can do following:
(\w)(?<=(?=(?:.*\1){n})^.*) where n is variable
Where:
(\w) — any character, captured in first group.(?<=^.*) — lookbehind assertion, which return us to the start of the string.(?=(?:.*\1){n}) — lookahead assertion, to see if string have n instances of that character.Demo