I'm not sure that Java supports the full implementation of regular expressions, but if so, you can use:
(\d)(\1)002345
\1 means a backward reference to the first match (brackets-ed), so (\d)(\1) will match two identical numbers in series.
If Java does not support this, I suggest you hard code it, since you have only 3 categories.
source share