Is there a way to evaluate regular expressions in D, at compile time?
Asked
Active
Viewed 261 times
1 Answers
2
Use a static
variable of type std.regex.ctRegex
.

Adam D. Ruppe
- 25,382
- 4
- 41
- 60
-
I already tried that, but the returned Captures aren't available at compile time, and casting them immutable will not allow me to get the result. – Jeroen Apr 29 '14 at 21:07
-
What exactly are you doing? – Adam D. Ruppe Apr 29 '14 at 21:17
-
Evaluating if a string matches a regex and fetch the match. – Jeroen Apr 29 '14 at 21:17
-
2Hmm, interesting, the straightforward CTFE of plain regex doesn't work since it uses malloc! Rewriting it is a bit of a pain for that to, blargh. – Adam D. Ruppe Apr 29 '14 at 22:18
-
I took a shot at it but then you run into issues with casting pointers, which doesn't work with CTFE... – Vladimir Panteleev Apr 29 '14 at 22:27
-
1Yeah, and it does this throughout the file too. I think the best option here is to not use regex here... – Adam D. Ruppe Apr 29 '14 at 22:29
-
@AdamD.Ruppe Any alternatives? – Jeroen Apr 30 '14 at 10:25
-
The best option that comes to mind is to break down the regex into simpler string functions like indexOf etc. – Adam D. Ruppe Apr 30 '14 at 15:06