[Issue 15489] regex - match/matchAll and bmatch - different output

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Apr 6 05:53:49 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=15489

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

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

--- Comment #4 from Dmitry Olshansky <dmitry.olsh at gmail.com> ---
Ivan Kazmenko (In reply to Ivan Kazmenko from comment #0)
> I want to test for the pattern "two consecutive characters, arbitrary
> sequence, the same two consecutive characters".  My pattern is r"(..).*\1". 
> It works with bmatch but not with match/matchAll.  A complete example
> follows.
> 
> import std.regex, std.stdio;
> void main ()
> {
> 	writeln (bmatch   ("abab",  r"(..).*\1"));  // [["abab", "ab"]]
> 	writeln (match    ("abab",  r"(..).*\1"));  // [["abab", "ab"]]
> 	writeln (matchAll ("abab",  r"(..).*\1"));  // [["abab", "ab"]]
> 	writeln (bmatch   ("xabab", r"(..).*\1"));  // [["abab", "ab"]]
> 	writeln (match    ("xabab", r"(..).*\1"));  // []
> 	writeln (matchAll ("xabab", r"(..).*\1"));  // []
> }
> 
> As you can see, bmatch (usage discouraged in the docs) gives me the result I
> want, but match (also discouraged) and matchAll (way to go) don't.
> 

Well this boils down to :
a) Use what works for now.
b) You might have found a case where Thompson engine simply cannot produce the
right result.

Finally I should detect these patterns and switch between simple backtracking
and thompson engine.

--


More information about the Digitalmars-d-bugs mailing list