On 23/11/15 12:41 PM, yawniek wrote:
hi!

how can i format  a string with captures from a regular expression?
basically make this pass:
https://gist.github.com/f17647fb2f8ff2261d42


context: i'm trying to write a implementation for
https://github.com/ua-parser
where the regular expression as well as the format strings are given.

I take it that browscap[0] does it not do what you want?
I have an generator at [1].
Feel free to steal.

Also once you do get yours working, you'll want to use ctRegex and generate a file with all of them in it. That'll increase performance significantly.

Reguarding regex, if you want a named sub part use:
(?<text>[a-z]*)
Where [a-z]* is just an example.

I would recommend you learning how input ranges work. They are used with how to get the matches out, e.g.

auto rgx = ctRegex!`([a-z])[123]`;
foreach(match; rgx.matchAll("b3")) {
    writeln(match.hit);
}

Or something along those lines, I did it off the top of my head.

[0] https://github.com/rikkimax/Cmsed/blob/master/tools/browser_detection/browscap.ini [1] https://github.com/rikkimax/Cmsed/blob/master/tools/browser_detection/generator.d

Reply via email to