1 module nxt.static_regex; 2 3 /** Statically defined regular expression. 4 * 5 * See_Also: https://forum.dlang.org/post/mailman.4770.1596218284.31109.digitalmars-d-announce@puremagic.com 6 */ 7 auto staticRegex(string reStr)() 8 { 9 import std.regex : regex, Regex; 10 static struct Impl 11 { 12 @safe: 13 static typeof(return) re; 14 static this() 15 { 16 re = regex(reStr); 17 } 18 } 19 return Impl.re; 20 } 21 22 // 23 version(none) // disabled for now 24 @safe unittest 25 { 26 // string input; 27 scope x = staticRegex!("foo(\\w+)bar"); 28 // auto result = input.replaceAll(x, `blah $1 bleh`); 29 }