That is exactly, what the documentation to Regex.Unescape is saying. It throws an Argument exception, when it comes to an escape sequence that it cannot convert, like \d
.
The Regex.Unescape
methods converts string escape sequences with the appropriate characters itself, e.g. \n
with 0x0A
.
You don't need to use the Regex.Unescape
method here.
String exp = "^\\d\\d*$";
Regex r = new Regex(exp);
is just fine.
Or the verbatim version:
String exp = @"^\d\d*$";
Regex r = new Regex(exp);