Regex backend refactoring/rewriting?

Stephen M. Webb stephen.webb@bregmasoft.ca
Thu Feb 19 11:36:00 GMT 2015


On 02/19/2015 12:25 AM, Tim Shen wrote:
> [...]
> 
> Additionally, I noticed that our POSIX executer is not conforming:
> 
>     #include <regex>
>     #include <iostream>
> 
>     using namespace std;
> 
>     int main() {
>         cmatch m;
>         cout << regex_search("aaaaaaaa", m, regex("a*(a*)",
> regex_constants::extended)) << "\n";
>         for (const auto& it : m) {
>             cout << it << "\n";
>         }
>     }
> 
> it prints:
> 1
> aaaaaaaa
> /* here is an empty string */
> but it should print:
> 1
> aaaaaaaa
> aaaaaaaa
> 
> since POSIX requires leftmost longest match
> (http://pubs.opengroup.org/onlinepubs/7908799/xbd/re.html), and the
> latter captured (a*) should take all 'a's.

But, a leftmesot longest match would have consumes all the input with the fist "a*", leaving an empty match for the
second "a*" and thus an empty capture.  Consider what "(a*)(a*)" would print for the same input.

-- 
Stephen M. Webb  <stephen.webb@bregmasoft.ca>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20150219/0d2f3c73/attachment.sig>


More information about the Libstdc++ mailing list