Comment #0 by bearophile_hugs — 2013-01-24T18:52:04Z
This is a low-priority enhancement request (meta-enhancement request: in Bugzilla I'd like different tags for different enhancement request priorities).
This code works:
import std.stdio, std.regex;
void main() {
auto r = regex(r"\d+", "g");
"10 20 30".match(r).writeln();
}
And prints:
[["10"], ["20"], ["30"]]
While this code:
import std.stdio, std.regex;
void main() {
const r = regex(r"\d+", "g");
"10 20 30".match(r).writeln();
}
Shows (dmd 2.062alpha):
test.d(4): Error: template std.regex.match does not match any function template declaration. Candidates are:
...\dmd2\src\phobos\std\regex.d(6532): std.regex.match(R, RegEx)(R input, RegEx re) if (isSomeString!(R) && is(RegEx == Regex!(BasicElementOf!(R))))
...\dmd2\src\phobos\std\regex.d(6539): std.regex.match(R, String)(R input, String re) if (isSomeString!(R) && isSomeString!(String))
...\dmd2\src\phobos\std\regex.d(6545): std.regex.match(R, RegEx)(R input, RegEx re) if (isSomeString!(R) && is(RegEx == StaticRegex!(BasicElementOf!(R))))
...\dmd2\src\phobos\std\regex.d(6532): Error: template std.regex.match cannot deduce template function from argument types !()(string,const(Regex!(char)))
I suggest to support constant regex, if possible. (In D code I like to mark everything as not mutable unless it has to mutate).