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 countr开发者_Go百科y 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".
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.
精彩评论