Possible Duplicate:
Regular Expression for Phone Number
I'm kinda new to regular expressions, so I don't quite yet know its possibilites. Therefore, I don't know whether it will be difficult or not to solve this problem.
I have very liberally formatted phone strings and need to format them in a fixed way (at least try my best). "899-123-4-45; 22-56-87", "5 99-25-31-71", "577-345-678,274-89-56".
Here's the info I know:
New landline phones start with 2-XX-XX-XX followed by 6 numbers (between them can be two type of delimiters either "-" or " " number of them is not known).
Old landline phones only contain 6 numbers XX-XX-XX.
Old cellphone codes contain 8XX-YY-YY-YY 9 numbers. The first one is 8. XX is the operator's code (don't know all of them).
New cellphone codes contain 5XX-YY-YY 9 numbers, the only difference is the first number.
Some records contain old landline codes, new landline codes, old cellphone codes and new cellphone codes.
I need to store all numbers in new format, with only two delimiters "-" and ",". ex: "599-12-34-56,2-45-61-34", "2-45-65-12", "574-12-34-56".
I just don't know where to start. Should I try to split big strings with only the ones that contain numbers and then retrieve only the number and determine which format it is? Or is there a simpler solution?
How would you parse this string: "574-12-34-56; 2 456 324, 455-566 2 22 40 56"? First split these into 3 parts? Can I split it with either ";" or " " or ","? Then should I retrieve only numbers and determine their style and format it properly?