2017-02-10 3 views
1

일부 정규 표현식을 사용하려고하면 "분할 오류"가 발생합니다. 이 예에서 첫 번째 정규 표현식은 잘 작동하지만, 두 번째는 세그먼트 오류 발생 :세그먼트 오류 C++ 정규식

g++ -O0 -g -Wall -Wpedantic -std=c++11 try3.cpp -o try3 

을 그리고 그것을 실행할 때이 얻을 :

#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; 
} 

내가 같이 컴파일

을 내가 된 libstdc와 5.11을 해제에 CentOS에서 실행하고
$ ./try3 
<.*>.*</.*>, <tag>value</tag>=found 
About to create the regex! 
Segmentation fault 

는 ++ - 이것은 GC 때문에 4.1.2-55.el5

+0

를 참조하십시오. 당신이 그 라인 주위에 try/catch를 넣으면 이것을 알 수 있지만 잡히지는 않습니다. – sln

+0

@sln : true, try 문을 사용하여 이전에 시도했지만 아무 것도 잡을 수 없습니다. 당신 (또는 다른 사람들)이 임시 해결책을 가지고 있습니까? –

+0

확실하지는 않지만 google 문제는 lib 버전이거나 컴파일 할 때 설정된 플래그 일 것입니다. 누군가는 확실히 알고 있어야합니다. – sln

답변