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.

链接地址: http://www.djcxy.com/p/31542.html

上一篇: 在这种情况下,为什么Python比C ++更快?

下一篇: 正则表达式库在c ++中无法正常工作