How can I replace a regex substring match in Javascript?

Or if you're sure there won't be any other digits in the string.

Var str = 'asd-0. Testing'; var regex = /(asd-)\d(\. \w+)/; str = str.

Replace(regex, "$11$2"); console. Log(str); Or if you're sure there won't be any other digits in the string: var str = 'asd-0. Testing'; var regex = /\d/; str = str.

Replace(regex, "1"); console. Log(str).

Using 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.

I want to replace the substring with '1' not the entire string with the substring – dave Aug 30 '10 at 5:46.

I would get the part before and after what you want to replace and put them either side. Like: var str = 'asd-0. Testing'; var regex = /(asd-)\d(\.

\w+)/; var matches = str. Match(regex); var result = matches1 + "1" + matches2.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions