ctRegex - named submatch
Dmitry Olshansky
dmitry.olsh at gmail.com
Tue Aug 7 13:51:24 PDT 2012
On 08-Aug-12 00:24, Daniel wrote:
> Hi,
>
> I tried using named submatch for ctRegex... it works but seemingly only
> for maximum 1 named submatch...
>
Great! I never tried ;) Should just work though...
> OK (\w changed to \S to avoid, out of memory)
> `(?P<var>\S+)\s*=\s*(\d+);`
> `(?\S+)\s*=\s*(?P<value>\d+);`
>
> NOT OK
> `(?P<var>\w+)\s*=\s*(?P<value>\d+);`
>
Would be great to know what exactly is not OK :) Error message etc.
> Is this a known bug? I used the regex example from the Library
> Reference, converting it to ctRegex...
I know it's hitting assert failure during parse. It's a CTFE bug, there
are some other limitations but they are not in bugzilla yet.
That all being said experimental tag on ctRegex in DDoc is here for a
reason, and that is: ctRegex can't compile nor match full regex testsuite.
(out of memory + bugs)
>
> Lookup named submatch.
> import std.regex;
> import std.range;
>
> auto m = match("a = 42;", regex(`(?P<var>\w+)\s*=\s*(?P<value>\d+);`));
> auto c = m.captures;
> assert(c["var"] == "a");
> assert(c["value"] == "42");
> popFrontN(c, 2);
> //named groups are unaffected by range primitives
> assert(c["var"] =="a");
> assert(c.front == "42");
>
--
Dmitry Olshansky
More information about the Digitalmars-d-learn
mailing list