views:

30

answers:

1

Ok the question is quite simple. I'm looking for a string like this one :

name="some_text_0_some_text"

I have HTML code before and after the string above.

Now i would like to replace the 0 by something like : !NEW_ID!

So i made a simple regex :

.*name="\w+(\d+)\w+".*

But i don't see how to replace exclusively the captured block.

Is there a way to replace a captured result like ($1) by some other string ?

The result would be :

name="some_text_!NEW_ID!_some_text"

Thanks for your help :)

+1  A: 

A solution is to add captures for the preceding and following text:

str.replace(/(.*value="\w+)(\d+)(\w+".*)/, "$1!NEW_ID!$3")
Matthew Flaschen