digitalmars.D.learn - Is std.regex.match completely broken?
- Jacob Carlborg (12/12) Feb 28 2011 The following code will result in an AssertError or RangeError when run.
- Dmitry Olshansky (11/21) Mar 01 2011 Well, there won't be a match.
- Jacob Carlborg (6/30) Mar 01 2011 That seems quite strange, to design an API like that. Why doesn't "hit"
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? -- /Jacob Carlborg
Feb 28 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
Mar 01 2011
On 2011-03-01 14:03, Dmitry Olshansky wrote:On 28.02.2011 22:37, Jacob Carlborg wrote:That seems quite strange, to design an API like that. Why doesn't "hit" just returns an empty string and "captures" an empty range.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.Sounds good. -- /Jacob Carlborg
Mar 01 2011