Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving a phone number from a string with regular expressions
    text
    copied!<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5013782/regular-expression-for-phone-number">Regular Expression for Phone Number</a> </p> </blockquote> <p>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.</p> <p>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".</p> <p>Here's the info I know:</p> <p>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).</p> <p>Old landline phones only contain 6 numbers XX-XX-XX.</p> <p>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).</p> <p>New cellphone codes contain 5XX-YY-YY 9 numbers, the only difference is the first number.</p> <p>Some records contain old landline codes, new landline codes, old cellphone codes and new cellphone codes.</p> <p>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".</p> <p>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?</p> <p>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?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload