Reputation: 11
I am new to regular expressions. I am looking for String which have only repeated characters like (aaa or bbb) from A to Z.
I am using @"\b[a-z]{1}(.){1,}\b"
which is partially working. Not completely.
I would appreciate if anyone help me in this regard.
Thanks.
Upvotes: 0
Views: 54
Reputation: 163287
You could capture the first character in a capturing group (group 1).
Then make sure the rest of the string contains the same character as the character captured in group 1 by using a backreference to group 1 like \1
:
Explanation
\b
Word boundary([a-zA-Z])
Match an upper or lowercase character in the first capturing group\1+
Repeat the first caturing group 1 or more times\b
Word boundaryUpvotes: 2