standardize international phone no. code using only regex

Posted by DarkFox on Stack Overflow See other posts from Stack Overflow or by DarkFox
Published on 2010-03-21T16:13:32Z Indexed on 2010/03/21 16:21 UTC
Read the original article Hit count: 332

Filed under:
|
|

Sipdroid on Android has a search & replace method, that uses regex. I'm trying to use it to make sure all outgoing calls has a country code in the format 00XX

I also want it to put 0045 in front of the number, if no country code is present.

The first one, I have solved, but I can't figure out how to do the second thing.

Search:

\A(((\+)(\d{2})?)|(00(\d{2})?)|)((\d|\s)+)\Z

Replace:

00$4$6$7

I'm using http://www.regexplanet.com/simple/index.html to test it, with the test strings: "12345678", "+4512345678" and "004512345678" They should all return "004512345678".

© Stack Overflow or respective owner

Related posts about regex

Related posts about java