简体   繁体   中英

Regex library not working correctly in c++

I have been looking up places to work with regex in c++ , as I want to learn regular expressions in c++ (do give me a step by step link also if you guys have any). I am using g++ to compile my programs and working in Ubuntu. earlier my program were not compiling but then I read this post where it said to compile the program by "g++ -std=c++0x sample.cpp" to use the regex header. My first program works correctly, i tried implementing regex_match

#include<stdio.h>
#include<iostream>
#include<regex>
using namespace std;

int main()
{
string str = "Hello world";
regex rx ("ello");

if(regex_match(str.begin(), str.end(), rx))
{ 
cout<<"True"<<endl;
}
else
cout<<"False"<<endl;
return(0);
}

for which my program returned false ... ( as the expression is not matching completely) I also rechecked it by making it match...it works. Now I am writing another program to implement regex_replace and regex_search . Both of which doesnt work ( for regex_search just replace regex_match in the above program with regex_search. kindly help.I dont know where I am getting wrong.

The <regex> header is not fully supported by GCC.

You can see GCC support here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM