boost regex recursive quesion
This is my first time to using maillist I'm learning to use boost::regex for a month , a few days ago I found a problem( maybe is my mistake ?) I construct a simple recursive regular expression: a(?0)? This regex contains a recursive call (?0). It should match a string with any arbitrary length filled with 'a' characters. regex_match only returns true for "a" and "aa", but failed to match "aaa" and any string longer than three characters. Why? I try it on boost 1.45 and 1.57 , both get same result . I had sent this question on stackoverflow , but had not get a answer now . Is there any flag should be used with regex_match to use recursive call ? Thank you .
a(?0)?
This regex contains a recursive call (?0).
It should match a string with any arbitrary length filled with 'a' characters. regex_match only returns true for "a" and "aa", but failed to match "aaa" and any string longer than three characters.
Why?
It's a bug :( Unfortunately the "obvious" fix breaks a heck of a lot of other stuff. John.
Hello John , Thanks for your reply . Does it means that all of recursive calls should be avoid in regular expression ? I had tried another expression "\(((?>[^()]+)|(?0))*\)" which used to check parenthesis pair . I work well . So I think boost::regex support recursive calls . If it is a bug , this is a serious problem , why boost not make a caveat for it in document ? wenxibo
From: jz.maddock@googlemail.com Date: Mon, 23 Mar 2015 17:57:46 +0000 To: boost@lists.boost.org Subject: Re: [boost] boost regex recursive quesion
a(?0)?
This regex contains a recursive call (?0).
It should match a string with any arbitrary length filled with 'a' characters. regex_match only returns true for "a" and "aa", but failed to match "aaa" and any string longer than three characters.
Why?
It's a bug :(
Unfortunately the "obvious" fix breaks a heck of a lot of other stuff.
John.
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Does it means that all of recursive calls should be avoid in regular expression ? No, most things work - and are rather well tested actually. The bug relates to recursions with bounded repeats, so:
(?N)? or (?N){x,y}
If it is a bug , this is a serious problem , why boost not make a caveat for it in document ?
Because you only discovered the bug yesterday ;) John.
participants (2)
-
John Maddock
-
温西波