I have the following strings:
foo_0_13
foz[0][bar][]
far_0
I have a convention, and need to match from strings like foo_0_13
and far_2
the underscore and the digit following, example _0
or _2
... And for any string with structure foz[0][bar][]
or foz[3]
I need to match [0]
or [3]
I have tried ((\_\d)|\[\d\])
but this matched _0_1
, how can I make it match only _0
?
I need to find only the first occurrence of the "underscore-digit" combination.
Second part:
If I have an html division with multiple occurrence of _0
and [0]
as
<div id="foo_0_13" name="bar[0][xxx][]"> <p id="par_0">Test</p> </div>
and I need to replace all the these occurrence with _1
so that the html becomes
<div id="foo_1_13" name="bar[1][xxx][]"> <p id="par_1">Test</p> </div>
how can I elaborate this to get the desired html knowing that am using javascript?