digitalmars.D.learn - Regex problem
- seany (39/39) Jun 27 2014 Cosider this:
- H. S. Teoh via Digitalmars-d-learn (14/21) Jun 27 2014 [...]
Cosider this: ulong regexChk(string haystack, string needle) { // haystack and needle are okey auto r = regex(needle, "g"); auto m = match(haystack, r); // up to here is all fine return m.hit().count(); } I want to count the numbers needles is mathced in haystack But I get the error : core.exception.AssertError std.regex(5587): Assertion failure ---------------- ./niarbyl(_d_assertm+0x26) [0x4e6c26] ./niarbyl() [0x4f45be] ./niarbyl(pure nothrow property trusted immutable(char)[] std.regex.Captures!(immutable(char)[], ulong).Captures.hit()+0x61) [0x4c8af1] ./niarbyl(pure nothrow property trusted immutable(char)[] std.regex.__T10RegexMatchTAyaS273std5regex15ThompsonMatcherZ.Re exMatch.hit()+0x59) [0x4c7089] ./niarbyl(ulong niarbyl.regexChk(immutable(char)[], immutable(char)[])+0x87) [0x4ac85f] ./niarbyl(void niarbyl.setGrammarApllicability()+0x3e3) [0x4accbb] ./niarbyl(_Dmain+0x95) [0x4acd9d] ./niarbyl(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll().void __lambda1()+0x18) [0x4eab9c] ./niarbyl(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x4eaaf6] ./niarbyl(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll()+0x30) [0x4eab5c] ./niarbyl(void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate())+0x2a) [0x4eaaf6] ./niarbyl(_d_run_main+0x1a3) [0x4eaa77] ./niarbyl(main+0x17) [0x4dab0f] /usr/lib/libc.so.6(__libc_start_main+0xf0) [0x7fe35eb43000] I dont quite understand. I must be doing some rooki mistake. Help?
Jun 27 2014
On Fri, Jun 27, 2014 at 03:59:47PM +0000, seany via Digitalmars-d-learn wrote: [...]core.exception.AssertError std.regex(5587): Assertion failure ---------------- ./niarbyl(_d_assertm+0x26) [0x4e6c26] ./niarbyl() [0x4f45be] ./niarbyl(pure nothrow property trusted immutable(char)[] std.regex.Captures!(immutable(char)[], ulong).Captures.hit()+0x61) [0x4c8af1][...] Your code works fine on git HEAD, so it seems that this is a bug in std.regex that has since been fixed. It may not do what you *want*, though -- be aware that in the next release, match() will be deprecated and replaced by matchFirst and matchAll, which are more precise in what exactly you want to match. In any case, assertions inside Phobos code is most likely a Phobos bug, since it means that you've somehow managed to get it to go down a code path that the author thought would never happen. T -- Let's eat some disquits while we format the biskettes.
Jun 27 2014