Boost C++ Libraries: Ticket #2157: Xpressive end-of-line match broken https://svn.boost.org/trac10/ticket/2157 <p> End of line matching inside a string is broken, simple example: </p> <p> Subject: abc\ndef\nghi Regex: <sup>.+$ </sup></p> <p> I'm looking for "abc". The following xpressive-based code has odd results: </p> <p> string text(argv<a class="changeset" href="https://svn.boost.org/trac10/changeset/1" title="Import core sources for SVNmanger 0.38 ">[1]</a>); sregex rex = sregex::compile(text, regex_constants::not_dot_newline); </p> <p> smatch match; string subject("abc\ndef\nghi"); if (regex_search(subject.begin(), subject.end(), match, rex, regex_constants::match_default)) { </p> <blockquote> <p> std::cout &lt;&lt; "Match at: " &lt;&lt; match.position(0) &lt;&lt; " length: " &lt;&lt; match.length(0); </p> </blockquote> <p> } </p> <p> <sup>.+$: Match at: 8 length: 3 $: Match at: 4 length: 0 .$: Match at: 10 length: 1 </sup></p> <p> These definitely aren't right, it appears that the only place where end-of-line is matching is at end-of-string. Things get even stranger if I try to use Windows or Mac style end-of-line styles. If I use boost::regex instead then I get these results: </p> <p> <sup>.+$: Match at: 0 length: 3 $: Match at: 3 length: 0 .$: Match at: 2 length: 1 </sup></p> <p> These are the results I'd expect. It appears in Xpressive that the check in assert_line_base::is_line_break is broken, the following line: </p> <p> if(traits_cast&lt;Traits&gt;(state).isctype(ch, this-&gt;newline_)) </p> <p> checks the previous character to see if it's a line break. I believe this should check the current character: </p> <p> if(traits_cast&lt;Traits&gt;(state).isctype(*state.cur_, this-&gt;newline_)) </p> <p> This then gets me sane results: </p> <p> <sup>.+$: Match at: 0 length: 3 $: Match at: 3 length: 0 .$: Match at: 2 length: 1 </sup></p> <p> [note: Eric says that this patch is probably not correct as it causes regression failures] </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2157 Trac 1.4.3 Eric Niebler Wed, 30 Jul 2008 22:22:41 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2157#comment:1 https://svn.boost.org/trac10/ticket/2157#comment:1 <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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/47899" title="fixed buggy eol matching behavior (fixes #2157)">[47899]</a>) fixed buggy eol matching behavior (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2157" title="#2157: Bugs: Xpressive end-of-line match broken (closed: fixed)">#2157</a>) </p> Ticket Eric Niebler Wed, 30 Jul 2008 22:56:29 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/2157#comment:2 https://svn.boost.org/trac10/ticket/2157#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> The fix is not quite right ... </p> Ticket Eric Niebler Wed, 30 Jul 2008 23:21:44 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2157#comment:3 https://svn.boost.org/trac10/ticket/2157#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/47901" title="ok, really fix end-of-line handling (fixes #2157)">[47901]</a>) ok, really fix end-of-line handling (fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2157" title="#2157: Bugs: Xpressive end-of-line match broken (closed: fixed)">#2157</a>) </p> Ticket