1

Topic: std:: regex phone number parsing

All greetings! With  I am on friendly terms as so far as. There is a question, to get phone number. But a problem most likely with ignorance std:: regex.//phone std:: string pattern (R "(^ ((8 | \\+420) [\-]?)? (\\(? \\d {3} \\)? [\-]?)? [\\d \-] {7,10} $)"); std:: string data ("4207743822140"); std:: smatch match; try {if (std:: regex_match (data, match, pattern)) {//here in match it is had 5 coincidence//and for example, match [3] looks here so in hmm/match [3].matched = true//match [3].first = "420"//it is the iterator?//match [3].second = "7743822140"//it is the iterator? const std:: string s1 =...;//here here I want here it is "7743822140",//how to get?}} catch (const std::regex_error& e) {//smth. wrong}

2

Re: std:: regex phone number parsing

Hello, Dead Down, you wrote: > All greetings! > With  I am on friendly terms as so far as. There is a question, to get phone number. But a problem most likely with ignorance std:: regex. Once very much for a long time solved such task when did a plug-in for  with illumination of telephone numbers. The main point at designing was - and what to consider as phone number? But in my case it was necessary to refuse from  in favor of manual parsing for when there were many phones and many tabs, ff began strongly .

3

Re: std:: regex phone number parsing

Hello, Dead Down, you wrote: >//match [3].first = "420"//it is the iterator? >//match [3].second = "7743822140"//it is the iterator? It, seemingly, iterators on here this group (8 | \\+420), the first on the beginning of the line, the second group on the end to Get somehow so, const std:: string s1 = (match [3].first, match [3].second); but, probably, the group 3, and group 0 - all expression, or 1 - everything that in root brackets is necessary not.

4

Re: std:: regex phone number parsing

Hello, Alexander G, you wrote: AG> but, probably, the group 3, and group 0 - all expression, or 1 - everything that in root brackets is necessary not. More likely 4: std:: string const s1 (match [4].first, match [4].second);

5

Re: std:: regex phone number parsing

Hello, Dead Down, you wrote: > > std:: string pattern (R "(^ ((8 | \\+420) [\-]?)? (\\(? \\d {3} \\)? [\-]?)? [\\d \-] {7,10} $)"); > Well you either a dagger put on, or cowards of that. In sense, or \\in a normal literal, or R ("") and then it is possible normal single \to put.

6

Re: std:: regex phone number parsing

Hello, Dead Down, you wrote: > All greetings! > With  I am on friendly terms as so far as. There is a question, to get phone number. But a problem most likely with ignorance std:: regex. It is a pity that you did not give the verbal description of the task, after all from unoperated  it is possible to misunderstand. If I only correctly understood a condition the decision can be such: https://ideone.com/69RjO3 #include <iostream> #include <regex> std:: string exptract_phone_number (const std::string& input) {const std:: regex pattern (R "(^ (8 | \+? 420) \s* \-?\s * (? sad \d {3}) | \((\d {3}) \)) \s* \-?\s * (\d {7}) $)"); std:: smatch match; return std:: regex_match (input, match, pattern)? match [2].str () + match [3].str () + match [4].str (): "";} int main () {std:: cout <<exptract_phone_number ("4207743822140") <<std:: endl; std:: cout <<exptract_phone_number ("+420-7743822140") <<std:: endl; std:: cout <<exptract_phone_number ("+420- (774 3822140") <<std:: endl; std:: cout <<exptract_phone_number ("+420774-3822140") <<std:: endl; std:: cout <<exptract_phone_number ("+420 (774)-3822140") <<std:: endl; std:: cout <<exptract_phone_number ("+420-774-3822140") <<std:: endl; std:: cout <<exptract_phone_number ("+420- (774)-3822140") <<std:: endl; std:: cout <<exptract_phone_number ("87743822140") <<std:: endl; std:: cout <<exptract_phone_number ("8-7743822140") <<std:: endl; std:: cout <<exptract_phone_number ("8(774) 3822140") <<std:: endl; std:: cout <<exptract_phone_number ("8774-3822140") <<std:: endl; std:: cout <<exptract_phone_number ("8 (774)-3822140") <<std:: endl; std:: : cout <<exptract_phone_number ("8-774-3822140") <<std:: endl; std:: cout <<exptract_phone_number ("8 (774)-3822140") <<std:: endl;}

7

Re: std:: regex phone number parsing

Hello, rg45, you wrote: R> It is a pity that you did not give the verbal description of the task, after all from unoperated  it is possible to misunderstand. If I only correctly understood a condition the decision can be such: Super! It is direct that that is necessary! Thanks huge! The task in the project closed, your copyright attributed, left in .

8

Re: std:: regex phone number parsing

Hello, Dead Down, you wrote: > the Task in the project closed, your copyright attributed, left in . There a misprint still to correct: "exptract".