Link to home
Start Free TrialLog in
Avatar of John (Yiannis) Toutountzoglou
John (Yiannis) ToutountzoglouFlag for Greece

asked on

Regular Expression

I do not have expirience about Reg's and i need some help
this Regular :
\((?<AreaCode>\d{3})\)\s*(?<Number>\d{3}(?:-|\s*)\d{4})

Open in new window

gives me a result like (800) 325-3535 or (210) 556 3535
i need a regular expression like +30 (210) 5563535
First part is an international code (max 9 digit plus + at the begging)
second part is area Code max 6 digit within parenthesis
third part is the actual tel number max 10 digits
Avatar of crysallus
crysallus
Flag of Australia image

This should match your current examples, as well as with the international extension added. In other words the international code is defined as optional here.

(?:(?<IntCode>\+\d{1,9}?)\s*)?\((?<AreaCode>\d{3})\)\s*(?<Number>\d{3}(?:-|\s*)\d{4})

Open in new window

If you don't want the international code to be optional, and only match numbers with the international code, then try this:

(?<IntCode>\+\d{1,9}?)\s*\((?<AreaCode>\d{3})\)\s*(?<Number>\d{3}(?:-|\s*)\d{4})

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of crysallus
crysallus
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John (Yiannis) Toutountzoglou

ASKER

You got it in your second post ...
thank you very much ....
i try to inert a specified Set of [0-9] to accept only numbers and it Match also if with letter...
"Your Syntax is correct.." ..i try this
\+(?<IntCode>\d{1,9}?[0-9])\s*\((?<AreaCode>\d{1,6}?[0-9])\)\s*(?<Number>\d{1,10}?[0-9])

Open in new window

What am i missing?
For example if i set +30 (210) 5564fffff then it return true....
My expression is
\+(?<IntCode>\d{1,9}?)\s*\((?<AreaCode>\d{1,6})\)\s*(?<Number>\d{1,10})

Open in new window