d - Execute compile time-compiled regex at compile time -
i compile error when try compile code: import std.regex; enum truth = "baba".matchfirst(ctregex!`[ab]+$`) ? true : false; void main() {} /usr/local/cellar/dmd/2.067.1/include/d2/std/regex/package.d(671): error: malloc cannot interpreted @ compile time, because has no available source code how around this? you can't, regex can compiled @ compile time, not run. you'll have write match other way, maybe combination of indexof or other simpler functions. (the reason isn't because regex complicated, because internally calls malloc efficiency, not supported @ compile time since external c function.) understanding ctregex needs explanation phobos' regular expression engine. works in 2 steps: given regular expression, first compiles bytecode, match on string, runs code. in ordinary regex , both steps happen @ runtime. when construct regex object, compiles bytecode. then, when match on string, runs code. with ctregex , first part happens @ com