Parsing a random string looking for repeating sequences using Java and Regex.
Consider strings:
aaabbaaacccbb
I\'d like to find a regular expression
This seems to work, though it gives subsequences as well:
(To be fair, this was built off of Guillame's code)
public static void main(final String[] args) {
// final String s = "RonRonJoeJoe";
// final String s = "RonBobRonJoe";
final String s = "aaabbaaacccbb";
final Pattern p = Pattern.compile("(.+).*\\1");
final Matcher m = p.matcher(s);
int start = 0;
while (m.find(start)) {
System.out.println(m.group(1));
start = m.toMatchResult().end(1);
}
}