It really depends on your server-side code, but essentially your problem is what \dis evaluated in the string as an escaped character. My solution is specific to PHP, but other server languages should have similar ones.
// drop the enclosing slashes, either here or in JS land
$jsPattern = addslashes("^9\d+$");
// $jsPattern => "^9\\d+$"
Now on the JS side you can use this:
var js_exp = new RegExp(js_pattern);
The easiest option is to simply remove the enclosed slashes and add an additional slash slash yourself if you can.
source
share