I am getting a "Segmentation fault" when I try to use some regular expressions. In this example, the first regular expression worked fine, but the second produced a segmentation fault:
#include <regex>
#include <iostream>
using namespace std;
void out(const string& s, const string& d,bool b) { cout << s << ", " << d << (b ? "=found" : "=not found") << endl; }
int
main()
{
const auto exp1 = string{"<.*>.*</.*>"};
const auto reg1 = regex{exp1};
const auto data1 = string{"<tag>value</tag>"};
const auto found1 = regex_match(data1, reg1);
out(exp1, data1, found1);
const auto exp2 = string{"<(.*)>.*</\\1>"};
cout << "About to create the regex!" << endl;
const auto reg2 = regex{exp2};
cout << "done." << endl;
const auto data2 = string{"<tag>value</tag>"};
const auto found2 = regex_match(data2, reg2);
out(exp2, data2, found2);
cout << "All done!" << endl;
}
I compile it like this:
g++ -O0 -g -Wall -Wpedantic -std=c++11 try3.cpp -o try3
And when I run it I get this:
$ ./try3
<.*>.*</.*>, <tag>value</tag>=found
About to create the regex!
Segmentation fault
I am running on CentOS release 5.11 with libstdc++-4.1.2-55.el5