Is std.regex.match completely broken?
Dmitry Olshansky
dmitry.olsh at gmail.com
Tue Mar 1 05:03:37 PST 2011
On 28.02.2011 22:37, Jacob Carlborg wrote:
> The following code will result in an AssertError or RangeError when run.
>
> import std.regex;
> import std.stdio;
>
> void main ()
> {
> auto m = "abc".match(`a(\w)b`);
>
> writeln(m.hit); // AssertError in regex.d:1795
> writeln(m.captures); // RangeError in regex.d:1719
> }
>
> Should I report this as a bug?
>
Well, there won't be a match.
If you meant "abc".match(`a(\w)c`) then it works for me.
At the bottom of it all, I also was sort of surprised to get an Assert
and not an Exception, but it's the way it works with ranges in Phobos.
So you should check m.empty before use.
P.S. I'm in the process of patching in lookahead regexes, I think I can
get them fairly soon. As for lookbehind, well, that's would be somewhat
harder it seems.
--
Dmitry Olshansky
More information about the Digitalmars-d-learn
mailing list