var str = \'asd-0.testing\'; var regex = /asd-(\\d)\\.\\w+/; str.replace(regex, 1);
That replaces the entire string str with
str
using str.replace(regex, $1);:
str.replace(regex, $1);
var str = 'asd-0.testing'; var regex = /(asd-)\d(\.\w+)/; if (str.match(regex)) { str = str.replace(regex, "$1" + "1" + "$2"); }
Edit: adaptation regarding the comment