Regex expression in C ++ not working properly

Below is an example of a regex expression when using perl, but it does not match when using C ++. After reading the std :: regex class information at cplusplus.com, I may have to use regex_search. If I do not use flags in regex_match. Using regex_search seems to complicate the simple match I want to complete. I would like the match to be on line 1 similar to perl. Is there another line approach for doing regular matches in C ++?

C ++

std::string line1 = "interface GigabitEthernet0/0/0/3.50 l2transport";
if (std::regex_match(line1, std::regex("/^(?=.*\binterface\b)(?=.*\bl2transport\b)(?!.*\.100)(?!.*\.200)(?!.*\.300)(?!.*\.400).*$/")))
cout << line1;

Perl

my $line1 = "interface GigabitEthernet0/0/0/3.50 l2transport";
if ($line1 =~ /^(?=.*\binterface\b)(?=.*\bl2transport\b)(?!.*\.100)(?!.*\.200)(?!.*\.300)(?!.*\.400).*$/ )
    print $line1;

I could create a method and pass the search criteria to return true or false ....

(Note: the reason I want to use C ++ is because it is much faster) is interpreted as compiled

( 2017-05-16: ++ , Perl . script , . Perl , ++ . . ++ , boost.)

+4
3

, ++. , R aw String .

:

std::string line1 = "interface GigabitEthernet0/0/0/3.50 l2transport";
std::regex pattern (R"(^(?=.*\binterface\b)(?=.*\bl2transport\b)(?!.*\.100)(?!.*\.200)(?!.*\.300)(?!.*\.400).*$)");
if (std::regex_match(line1, pattern)) {
    std::cout << line1 << '\n';
}

, ++ , .

+4

@craig young - . "\" ++ "\"

++ "/", . , ...

if (std::regex_match(line1, regex("^(?=.*\\binterface\\b)(?=.*\\bl2transport\\b)(?!.*\\.100)(?!.*\\.200)(?!.*\\.300)(?!.*\\.400).*$")))
+3

1

...\b..., "...\\b...". , $s =~ "...\\b..." Perl, regex("...\\b...") ++.

2

/ . ( Perl , .) , , /.

Fixed and simplified

regex("^(?=.*\\binterface\\b)(?=.*\\bl2transport\\b)(?!.*\\.[1-4]00)")
+3
source

Source: https://habr.com/ru/post/1662211/


All Articles