Boost C++ Libraries: Ticket #13256: regex '([|&])\1?' with backreference fails to compile if regex::nosub flag used https://svn.boost.org/trac10/ticket/13256 <p> when compiling a regex with regex::nosubs flag set, a regex with a back reference fails with: </p> <p> Invalid back reference: specified capturing group does not exist. The error occurred while parsing the regular expression: '([|&amp;])&gt;&gt;&gt;HERE&gt;&gt;&gt;\1?'. </p> <p> Test program: </p> <p> #include &lt;boost/regex.hpp&gt; #include &lt;iostream&gt; #include &lt;exception&gt; </p> <p> using namespace std; </p> <p> int main(int argc, char <strong>argv) { </strong></p> <blockquote> <p> try { </p> <blockquote> <p> boost::regex::flag_type flags = boost::regex::ECMAScript; flags |= boost::regex::nosubs; boost::regex theRegex("([|&amp;])<br />1?", flags); cout &lt;&lt; "ok\n"; return 0; </p> </blockquote> <p> } catch (exception &amp;e) { </p> <blockquote> <p> cerr &lt;&lt; "exception: " &lt;&lt; e.what() &lt;&lt; "\n"; return 1; </p> </blockquote> <p> } </p> </blockquote> <p> } g++ -std=c++11 test-boost-regex-bug.cpp -o test-boost-regex-bug -l boost_regex </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13256 Trac 1.4.3 Gene Thomas <gene@…> Wed, 11 Oct 2017 09:08:00 GMT <link>https://svn.boost.org/trac10/ticket/13256#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/13256#comment:1</guid> <description> <p> Test program again </p> <div class="wiki-code"><div class="code"><pre> <span class="cp">#include</span> <span class="cpf">&lt;boost/regex.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;exception&gt;</span><span class="cp"></span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="p">;</span> <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span> <span class="p">{</span> <span class="k">try</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">regex</span><span class="o">::</span><span class="n">flag_type</span> <span class="n">flags</span> <span class="o">=</span> <span class="n">boost</span><span class="o">::</span><span class="n">regex</span><span class="o">::</span><span class="n">ECMAScript</span><span class="p">;</span> <span class="n">flags</span> <span class="o">|=</span> <span class="n">boost</span><span class="o">::</span><span class="n">regex</span><span class="o">::</span><span class="n">nosubs</span><span class="p">;</span> <span class="n">boost</span><span class="o">::</span><span class="n">regex</span> <span class="n">theRegex</span><span class="p">(</span><span class="s">&quot;([|&amp;])</span><span class="se">\\</span><span class="s">1?&quot;</span><span class="p">,</span> <span class="n">flags</span><span class="p">);</span> <span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;ok</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="k">return</span> <span class="mi">0</span><span class="p">;</span> <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="n">exception</span> <span class="o">&amp;</span><span class="n">e</span><span class="p">)</span> <span class="p">{</span> <span class="n">cerr</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;exception: &quot;</span> <span class="o">&lt;&lt;</span> <span class="n">e</span><span class="p">.</span><span class="n">what</span><span class="p">()</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">;</span> <span class="k">return</span> <span class="mi">1</span><span class="p">;</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div> </description> <category>Ticket</category> </item> </channel> </rss>