I have an alpha-numeric string and I want to check for pattern repetition in it just for the integers. And they should be continuous.
Example
- 12341234qwe should tell me 1234 is repeated.
- 1234qwe1234 should NOT tell me that 1234 is repeated since its not continuous.
- 12121212 should be treated as 12 being repeated as that is the first set which would be found being repeated. But if there is an algorithm which would find 1212 as the repeated set before 12 then I guess it has to perform the steps again on 1212.
What I thought was I can store the integer part by iterating and comparing it with ( <= '0' && >= '9') in a different StringBuilder. Then I read about performing FFT on the string and it shows the repeated patterns. But I have no idea on how to perform FFT in Java and look for the results, also, I was hoping to try to do this without going to Signal Processing. I read about KMP pattern matching but that only works with a given input. Is there any other way to do this?
You can take help of regex to solve this I think. Consider code like this:
OUTPUT:
Explanation:
Regex being used is
(\\d+?)\\1where