dcsimg
How to use regex???
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Jyri_Saastamoinen
Posted On:   Tuesday, November 23, 2004 12:12 AM

I'm a newbie in this case so I don't have much to say about this. But I need to use it with phonenumbers.

I need a pattern??? to modify these numbers.

For example if I had numbers:

358441111
0441111
00358441111

so I need a some pattern to get these numbers like

+358441111

How can I do that with regex?

Re: How to use regex???

Posted By:   Anonymous  
Posted On:   Friday, December 3, 2004 10:49 AM

Your specification is very unclear. However, let me guess: If you have a number of one of the following forms

AAABBBBBB
0BBBBBB
00AAABBBBBB


it should always be converted to

+AAABBBBBB


From the second case, it is clear that you need AAA as an input - it cannot be guessed. If the specification is exactly as above, you do not need regex - the following will suffice:

String convert(String in, String prefix) {
if (in.startsWith("00"))
return "+" + in.substring(2);
else if (in.startsWith("0"))
return "+" + prefix + in.substring(1);
else
return "+" + in;
]

However, I fear that you need something more general - please specify exactly (or in a few dozen examples) what you need (including spaces in the number strings, if they are relevant!) ... then someone might be able to help you.


Regards


Harald M.

About | Sitemap | Contact