Hello Programmers, In this post, you will know how to solve the HackerRank Split the Phone Numbers Solution. This problem is a part of the Regex HackerRank Series.HackerRank Split the Phone Numbers SolutionOne more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.HackerRank Split the Phone Numbers SolutionProblemThere is a list of phone numbers which needs the attention of a text processing expert. As an expert in regular expressions, you are being roped in for the task. A phone number directory can reveal a lot such as country codes and local area codes. The only constraint is that one should know how to process it correctly.A Phone number is of the following format[Country code]-[Local Area Code]–[Number]There might either be a ‘-‘ ( ascii value 45), or a ‘ ‘ ( space, ascii value 32) between the segmentsWhere the country and local area codes can have 1-3 numerals each and the number section can have 4-10 numerals each.And so, if we tried to apply the a regular expression with groups on this phone number: 1-425–9854706We’d get:Group 1 = 1Group 2 = 425Group 3 = 9854706You will be provided a list of N phone numbers which conform to the pattern described above. Your task is to split it into the country code, local area code and the number.Input FormatN, where N is the number of tests.This will be followed by N lines containing N phone numbers in the format specified above.Constraints1 <= N <= 20There might either be a hyphen, or a space between the segmentsThe country and local area codes can have 1–3 numerals each and the number section can have 4-10 numerals each.Output FormatYour output will contain N lines.CountryCode=[Country Code],LocalAreaCode=[Local Area Code],Number=[Number]Recommended TechniqueThis problem can be solved in many ways, however, try to solve it using regular expressions and groups in order to gain a hands on practice of the concepts involved.Sample Input21 877 263827791-011-23413627Sample OutputCountryCode=1,LocalAreaCode=877,Number=2638277CountryCode=91,LocalAreaCode=011,Number=23413627HackerRank Split the Phone Numbers Solutions in Cpp#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int t,i,j,f=0,c=0,k; string a; cin>>t; getline(cin,a); for(i=0;i<t;i++) { fflush(stdin); getline(cin,a); j=0; cout<<"CountryCode="; while(a.at(j)!=' ' && a.at(j)!='-') { cout<<a.at(j); j++; } j++; cout<<",LocalAreaCode="; while(a.at(j)!=' ' && a.at(j)!='-') { cout<<a.at(j); j++; } j++; cout<<",Number="; while(j<a.length()) { cout<<a.at(j); j++; } cout<<endl; } return 0; }HackerRank Split the Phone Numbers Solutions in Javaimport java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String[] args) { String delimiter = "(-| )"; String[] labels = {"CountryCode", "LocalAreaCode", "Number"}; Scanner scanIn = new Scanner(System.in); int cases = scanIn.nextInt(); scanIn.nextLine(); // Get rid of the \n after # of cases while(cases > 0){ String[] tokens; String line = scanIn.nextLine(); tokens = line.split(delimiter); String output = ""; for(int i = 0; i < tokens.length; i++){ output += labels[i]; output += "="; output += tokens[i]; if(i != 2){ output += ","; } } System.out.println(output); cases --; } } }HackerRank Split the Phone Numbers Solutions in Pythont=input() ar=['CountryCode=',',LocalAreaCode=',',Number='] for _ in xrange(t): ans='' s='' i=0 for c in (raw_input()+' '): if c== ' ' or c == '-': ans+=ar[i] ans+=s s='' i+=1 else:s+=c print ans HackerRank Split the Phone Numbers Solutions in JavaScriptprocess.stdin.resume(); process.stdin.setEncoding("ascii"); process.stdin.on("data", function (input) { input = input.match(/^(.*)$/igm); var n = parseInt(input[0]), strs = input.slice(1,n+1), r = /^([^ \-]+).([^ \-]+).([^ \-]+)$/ig; for (i=0, j=strs.length; i<j; i+=1) { process.stdout.write(strs[i].replace(r,'CountryCode=$1,LocalAreaCode=$2,Number=$3')+'\n'); } });HackerRank Split the Phone Numbers Solutions in PHP<?php $_fp = fopen("php://stdin", "r"); /* Enter your code here. Read input from STDIN. Print output to STDOUT */ fscanf($_fp, "%d\n", $count); for ($i = 0; $i < $count; ++$i) { $line = trim(fgets($_fp)); $comps = preg_split('/( |-)/', $line, $matches); echo "CountryCode=$comps[0],LocalAreaCode=$comps[1],Number=$comps[2]\n"; } ?>Disclaimer: This problem (Split the Phone Numbers) is generated by HackerRank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.Next: HackerRank The British and American Style of Spelling Solution Post navigationHackerRank Language Solution HackerRank The British and American Style of Spelling Solution