ctRegex with variable?
Jethro via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Apr 12 14:25:40 PDT 2017
Can regex's have variables in them? I'd like to create a ctRegex
but match on runtime strings that are known at runtime.
e.g.,
auto c = ctRegex~("x{var}")
where var is a variable that is passed at runtime. e.g., match(s,
c, "test") will replace var with test.
The reason is I basically have the same regex to match but each
one differs in a specific way. It would be nice to be able to use
a fast way to search since most of the regex is the same but only
the a single token differs(and these tokens are only known at
runtime).
I obviously can build the regex string at runtime like
auto var = "test"
auto c = Regex("x{"~var~"}");
or whatever... but this is much slower when only var changes.
More information about the Digitalmars-d-learn
mailing list