Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8702675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:42:44+00:00 2026-06-13T02:42:44+00:00

Possible Duplicate: Regular Expression for Phone Number I’m kinda new to regular expressions, so

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:42:46+00:00Added an answer on June 13, 2026 at 2:42 am

    The best solution (in my opinion) would be to use multiple regular expressions, each one for a different format. Regular expressions tend to grow quite large quite fast so maintaining them can be a daunting experience.

    What I would do would be to use something like these:

    • (2)[ -]+(\d{2})[ -]+(\d{2})[ -]+(\d{2}) to match the first pattern (new land line phones): 2-XX-XX-XX.
    • (\d{2})[ -]+(\d{2})[ -]+(\d{2}) to match the second pattern (old land line phones): 6 digits.
    • (8\d{2})[ -]+(\d{2})[ -]+(\d{2})[ -]+(\d{2}) to match the third pattern (old mobile phones): 8XX-YY-YY-YY.
    • (5\d{2})[ -]+(\d{2})[ -]+(\d{2})[ -]+(\d{2}) to match the fourth pattern (new mobile phones): 5XX-YY-YY-YY.

    You will have to use the above expressions to see which expression will match the format of the number you have entered. Note that these expressions assume that the numbers making up the phone number are separated by a white space () or a dash (-).

    If the pattern will match, the regular expression engine will also throw in the numbers making up the phone number into groups, denoted by the ( and ) brackets. You can then reconstruct the phone number in any way you wish by accessing these groups and create new strings representing the newly formatted phone.

    To see how you can use regular expression groups in Javascipt, please take a look here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Regular expression that matches valid IPv6 addresses Can any one know the
Possible Duplicate: Regular cast vs. static_cast vs. dynamic_cast I don't quite get when to
Possible Duplicate: Regular expression where part of string must be number between 0-100 I'd
Possible Duplicate: Converting user input string to regular expression javascript new regexp from string
Possible Duplicate: Regular expression: match all words except I need your help for using
Possible Duplicate: Interesting test of Javascript RegExp Regular expression test can't decide between true
Possible Duplicate: Regex to match URL Is there a regular expression to return a
Possible Duplicate: How to escape text for regular expression in Java Is there a
Possible Duplicate: A comprehensive regex for phone number validation Perhaps a forgiving JavaScript solution
Possible Duplicate: php regex , extract phone number from text/html I have following requirement.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.