digitalmars.D.learn - ctRegex with variable?
- Jethro (15/15) Apr 12 2017 Can regex's have variables in them? I'd like to create a ctRegex
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/12) Apr 12 2017 Sounds reasonable but the string would have to be constructed each time
- Jesse Phillips (4/8) Apr 13 2017 As mentioned by Ali, benchmark for your use case.
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.
Apr 12 2017
On 04/12/2017 02:25 PM, Jethro wrote:
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.
Sounds reasonable but the string would have to be constructed each time
match is called. It could reuse the same buffer... So, one needs to
profile to see how it performs and we expect you to implement and test
it please. ;)
Ali
Apr 12 2017
On Wednesday, 12 April 2017 at 21:25:40 UTC, Jethro wrote:
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}")
As mentioned by Ali, benchmark for your use case.
If var has common values (e.g. 1-1000). generate a ctRegex table
for those values and use runtime for any that aren't in the table.
Apr 13 2017









=?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> 