views:

205

answers:

1

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".

+2  A: 

You should be aware that country codes may well be 3 or even 4 digits long.

See the list of country calling codes for details.

The replacement you are after is quite context-sensitive, so I would guess it is not possible to solve it with a single regex (in a simple enough way to make it actually usable). Then again, I am not a regex guru.

Péter Török
Well damn. I didn't know.Guess that makes this almost impossible to pull off, I'll just make it replace + with 00 then
DarkFox
That probably isn't correct either, if you are concerned about it working for others, that is.
msw
My main problem is that all my phone numbers in my contact book has numbers in the format +45... but my SIP provider only supports 0045...
DarkFox