03-06-2018 02:03 AM
I have a list of phone number that including both Australia and oversea. the length of the phone number is undefined (can be anything)
I want to know if there is a smart way to find repeated pattern within any phone number without using regular expression.
for example: 04123123123 has repeated pattern 123123123
has repeated pattern 1212121212
03-06-2018 03:51 AM
Do the repetitions have to be consecutive, or could this be a repeating pattern: 1234123
Could a repeating pattern contain as few as four digits (the original two, plus one repetition)?
03-06-2018 09:59 AM
Well, it's not really clear what "obvious" means in this context. So here's an example of how to do this for three-digit sets of digits:
length repeated3 $ 3;
if length(phoneno) >= 6 then do k=1 to length(phoneno)-5;
repeated3 = substr(phoneno, k);
if index( substr(phoneno, k+3), repeated3) then output;
03-06-2018 03:22 PM
Hi Patrick, I thought there might be some mathematic tricks like 12121212 is divisible by 10101 that able to solve the issue.
May be. But especially because this is about the very common case of phone number validation I'd go for RegEx. There should be a lot of RegEx published on the Internet and you won't have to "invent" everything from scratch. Just search a bit and use the one closest to your needs as a starting point.