## how to find repeated pattern in phone number

Regular Contributor
Posts: 155

# how to find repeated pattern in phone number

Hi Experts,

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

or 1212121212

has repeated pattern 1212121212

thanks

Posts: 4,736

## Re: how to find repeated pattern in phone number

And why don't you want to use RegEx as that's the "ideal" syntax for anything pattern?

Super User
Posts: 6,763

## Re: how to find repeated pattern in phone number

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)?

Regular Contributor
Posts: 155

## Re: how to find repeated pattern in phone number

Yes it can has repeats like that . But I want to remove the one that obviously invalid phone number.
Super User
Posts: 6,763

## Re: how to find repeated pattern in phone number

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;

end;

Regular Contributor
Posts: 155

## Re: how to find repeated pattern in phone number

Hi Patrick, I thought there might be some mathematic tricks like 12121212 is divisible by 10101 that able to solve the issue.
Posts: 4,736

## Re: how to find repeated pattern in phone number

gyambqt wrote:
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.

Discussion stats
• 6 replies
• 124 views
• 0 likes
• 3 in conversation