[Issue 2108] regexp.d: The greedy dotstar isn't so greedy

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Apr 18 13:58:13 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=2108


Dmitry Olshansky <dmitry.olsh at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh at gmail.com


--- Comment #3 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2011-04-18 13:54:37 PDT ---
(In reply to comment #2)
> This is also an issue in Windows with std.regex using DMD 2.043
> 
> But I would like to add that it is always greedy prior to text. The first
> assert will fail since it was not non-greedy and the second is what it should
> be.
> 
> import std.regex;
> 
> void main() {
>    assert(match("Hello there you silly person you.",
>      regex(r"\b.+? you .+\w")).hit != "Hello there you silly");
> 
>    assert(match("Hello there you silly person you.",
>      regex(r"\b.+? you .+\w")).hit == "there you silly person");
> }

Actually it should be 
 assert(match("Hello there you silly person you.",
      regex(r"\b.+? you .+\w")).hit == "Hello there you silly person you");

Two points - \b also matches at the begining of input (if the first char is
\w), and the last .+ is greedy, and since '.' is certainly not a \w, we have
what we have.
Also tested at:
http://www.regextester.com/ 
http://www.regular-expressions.info/javascriptexample.html 
... etc.
P.S. The patch is coming ;)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list