3
#include <regex>
#include <iostream>

using namespace std;

void out(bool b)
{
    cout<< ( b ? "found" : "not found" )<<endl;
}

int main()
{

    // find XML/HTML-tagged value(tags before and after the value must match):
    //regex reg2("<(.*)>.*</\\1>");

    regex reg2(R"(<(.*)>.*</\1>)");
    bool found = regex_match("<tag>value</tag>",
            reg2);
    out(found);
}

$ g++ -g -std=c++11 regex1.cpp

$ ./a.out

Segmentation fault (core dumped)


$ gdb a.out core.12473 

GNU gdb (GDB) Fedora (7.6-30.fc19)
Reading symbols from /home/neo/code/regex/a.out...done.
[New LWP 12473]
Core was generated by `./a.out'.
Program terminated with signal 11, Segmentation fault.
#0  0x0804a352 in std::__detail::_StateSeq::_M_append (this=0xbf948a30, __rhs=...)
    at /usr/include/c++/4.8.1/bits/regex_nfa.tcc:157
157       _M_nfa[_M_end2]._M_next = __rhs._M_start;
Missing separate debuginfos, use: debuginfo-install glibc-2.17-11.fc19.i686 libgcc-4.8.1-1.fc19.i686 libstdc++-4.8.1-1.fc19.i686
(gdb) bt
#0  0x0804a352 in std::__detail::_StateSeq::_M_append (this=0xbf948a30, __rhs=...)
    at /usr/include/c++/4.8.1/bits/regex_nfa.tcc:157
#1  0x0804ea33 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:779
#2  0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#3  0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#4  0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#5  0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#6  0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#7  0x0804ea01 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_alternative (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:776
#8  0x0804dc21 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_M_disjunction (
    this=0xbf948c68) at /usr/include/c++/4.8.1/bits/regex_compiler.h:758
#9  0x0804ce38 in std::__detail::_Compiler<char const*, std::regex_traits<char> >::_Compiler (this=0xbf948c68, 
    __b=@0xbf948d34: 0x80538ff "<(.*)>.*</\\1>", __e=@0xbf948d0c: 0x805390c "", __traits=..., __flags=16)
    at /usr/include/c++/4.8.1/bits/regex_compiler.h:729
#10 0x0804bb51 in std::__detail::__compile<char const*, std::regex_traits<char> > (
    __b=@0xbf948d34: 0x80538ff "<(.*)>.*</\\1>", __e=@0xbf948d0c: 0x805390c "", __t=..., __f=16)
    at /usr/include/c++/4.8.1/bits/regex_compiler.h:1105
#11 0x0804b0bb in std::basic_regex<char, std::regex_traits<char> >::basic_regex (this=0xbf948d4c, 
    __p=0x80538ff "<(.*)>.*</\\1>", __f=16) at /usr/include/c++/4.8.1/bits/regex.h:388
#12 0x08049847 in main () at regex1.cpp:17
4

1 に答える 1

0

C++11 正規表現は、4.9 まで GCC で完全にサポートされていません (この記事の執筆時点での現在のトランク)。詳細については、http: //gcc.gnu.org/gcc-4.9/changes.htmlの「ランタイム ライブラリ (libstdc++)」セクションを確認してください。

于 2014-01-24T22:09:33.980 に答える