Boost C++ Libraries: Ticket #6213: Escaping close parentheses doesn't work in boost::regex https://svn.boost.org/trac10/ticket/6213 <p> Currently I am running Boost 1.47 on Scientific Linux 6 and cannot get the escaped close parentheses to match in a very simple expression. I can remove the escaped close parentheses and the regular expression will match, but with the escaped close parentheses, we never can get the if statement to work. I can put a small work around in our codebase, but I would expect this feature to work. Below is a example snippet of code: </p> <div class="wikipage" style="font-size: 80%"><div class="wiki-code"><div class="code"><pre><span class="kt">void</span> <span class="nf">MyFuction</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">val</span><span class="p">)</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">regex</span> <span class="n">expr1</span><span class="p">(</span><span class="s">&quot;(.*)</span><span class="se">\\</span><span class="s">((.*)</span><span class="se">\\</span><span class="s">)&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">regex</span> <span class="n">expr2</span><span class="p">(</span><span class="s">&quot;(.*)</span><span class="se">\\</span><span class="s">((.*)&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">cmatch</span> <span class="n">matches</span><span class="p">;</span> <span class="k">if</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">regex_match</span><span class="p">(</span><span class="n">val</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">matches</span><span class="p">,</span> <span class="n">expr1</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//never will get in here</span> <span class="p">}</span> <span class="k">if</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">regex_match</span><span class="p">(</span><span class="n">val</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">matches</span><span class="p">,</span> <span class="n">expr2</span><span class="p">))</span> <span class="p">{</span> <span class="c1">//will get in here when we expect it to</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div></div><p> I appologize if there's something on my side that I'm missing, but I searched around and really can't find anything in our code base that would indicate its our code base and not boost::regex. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/6213 Trac 1.4.3 Steven Watanabe Mon, 05 Dec 2011 17:11:39 GMT <link>https://svn.boost.org/trac10/ticket/6213#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6213#comment:1</guid> <description> <p> It seems to work with MSVC 10 with the trunk: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;string&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/regex.hpp&gt;</span><span class="cp"></span> <span class="kt">void</span> <span class="nf">f</span><span class="p">(</span><span class="k">const</span> <span class="n">std</span><span class="o">::</span><span class="n">string</span><span class="o">&amp;</span> <span class="n">val</span><span class="p">)</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">regex</span> <span class="n">expr1</span><span class="p">(</span><span class="s">&quot;(.*)</span><span class="se">\\</span><span class="s">((.*)</span><span class="se">\\</span><span class="s">)&quot;</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">cmatch</span> <span class="n">matches</span><span class="p">;</span> <span class="k">if</span><span class="p">(</span><span class="n">boost</span><span class="o">::</span><span class="n">regex_match</span><span class="p">(</span><span class="n">val</span><span class="p">.</span><span class="n">c_str</span><span class="p">(),</span> <span class="n">matches</span><span class="p">,</span> <span class="n">expr1</span><span class="p">))</span> <span class="p">{</span> <span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="s">&quot;matched&quot;</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span> <span class="p">}</span> <span class="p">}</span> <span class="kt">int</span> <span class="nf">main</span> <span class="p">()</span> <span class="p">{</span> <span class="n">f</span><span class="p">(</span><span class="s">&quot;test(test)&quot;</span><span class="p">);</span> <span class="p">}</span> </pre></div></div><p> I don't see any obvious recent changes that would affect this. Do you have an example string that fails to match? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Mon, 12 Dec 2011 22:36:57 GMT</pubDate> <title>component changed; owner set https://svn.boost.org/trac10/ticket/6213#comment:2 https://svn.boost.org/trac10/ticket/6213#comment:2 <ul> <li><strong>owner</strong> set to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">regex</span> </li> </ul> Ticket John Maddock Sat, 24 Dec 2011 17:55:58 GMT <link>https://svn.boost.org/trac10/ticket/6213#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/6213#comment:3</guid> <description> <p> As Steven says, we need to see the string that failed to match to tell you what's going on. My suspicion is that the string has content <em>after the closing ")"</em> in which case regex_match <em>will</em> fail (remember regex match only succeeds if the <em>whole</em> of the text was matched). </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Sat, 07 Jul 2012 18:13:47 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/6213#comment:4 https://svn.boost.org/trac10/ticket/6213#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> <p> Closed pending further information from the user. </p> Ticket