Can anyone give me a Java regex to identify repeated characters in a string? I am only looking for characters that are repeated immediately and they can be letters or digits.
Example:
abccde <- looking for this (immediately repeating c’s)
abcdce <- not this (c’s seperated by another character)
Try
'(\\w)\\1+'The
\\wmatches any word character (letter, digit, or underscore) and the\\1+matches whatever was in the first set of parentheses, one or more times. So you wind up matching any occurrence of a word character, followed immediately by one or more of the same word character again.(Note that I gave the regex as a Java string, i.e. with the backslashes already doubled for you)