Click here to Skip to main content
15,063,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i Have that expression for matching phone numbers:
Quote:
@"(\+[0-9]{2}|\+[0-9]{2}\(0\)|\(\+[0-9]{2}\)\(0\)|00[0-9]{2}|0)([0-9]{9}|[0-9\-\s]{9,18})";



but i want to identify German phone number from text file:
formats are: 0176/21425679
0157764123813
09621 11 85 45
0172 8622111
08103 / 30 444 30
+49 176 3123 8343

how can identify these type of phone numbers.
my expression working but not exactly.

What I have tried:

C#
<pre>@"(\+[0-9]{2}|\+[0-9]{2}\(0\)|\(\+[0-9]{2}\)\(0\)|00[0-9]{2}|0)([0-9]{9}|[0-9\-\s]{9,18})";



C#
Posted
Updated 19-Apr-18 5:10am
Comments
PIEBALDconsult 19-Apr-18 9:13am
   
And do they have nothing like 1-800-FLOWERS?

At first it depends on what you need:
Just verify if it is a valid (German) phone number or get the number in a defined format.

In any case it might be better to split the processing into multiple parts.

So you might for example replace the optional international prefix with a single '0' at first:
/^\+[0-9]{2}[^0-9]*/0/
# or
/^\+[0-9]{2}[ -/]*/0/
If you need to get the area code separately look for the next non-digit character. But that will not work for all inputs.

Finally remove all separation / delimiter characters (space, minus, slash). The final string should contain digits only and can be checked for min. and max. allowed length.
   
Quote:
how can identify these type of phone numbers.

You can never know if a number is a phone number or look like a phone number, it depend on context.
As fa as I know, German phone number comes with different number of digits.
+49 is the international header to Germany.
Spaces and dashes are artificial separators depending on user, and grouping can differ to make number easier to remember.
I would try something like:
((\+49[ /]*)?(\d[ /]*){10,11}\d)

Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
RegExr: Learn, Build, & Test RegEx[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
   
Comments
Member 11570633 22-Apr-18 13:01pm
   
Thanks working.
Patrice T 22-Apr-18 14:26pm
   
Can you accept one of the answers, it say to everyone that the question is solved.
Member 11570633 22-Apr-18 14:29pm
   
Accepted thanks.
Patrice T 22-Apr-18 14:30pm
   
Thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900