0

This is my string

<input name="e8[1][4]" value="" type="hidden">
<input name="e10[1][4]" value="" type="hidden">
<input name="e8[1][4]" value="" type="hidden">
<input name="e10[1][4]" value="" type="hidden">
<input name="e6[1][4]" value="" type="hidden">
<input name="e9[1][4]" value="" type="hidden">
<input name="e6[1][4]" value="" type="hidden">

I have to change all second array element with +1. it shoud be my output

<input name="e8[1][5]" value="" type="hidden">
<input name="e10[1][5]" value="" type="hidden">
<input name="e8[1][5]" value="" type="hidden">
<input name="e10[1][5]" value="" type="hidden">
<input name="e6[1][5]" value="" type="hidden">
<input name="e9[1][5]" value="" type="hidden">
<input name="e6[1][5]" value="" type="hidden">

How I achieve this format with jquery or regexsolution. i make following regex to get last number of string how i work ahead

var patt1 = /(\d+)(?!.*\d)/;
5
  • why dont you use replace [4] by [5] Commented Apr 3, 2014 at 5:10
  • Regex doesn't convert your groups to any value other than string. You'd need to convert to int to add +1 to all the values Commented Apr 3, 2014 at 5:10
  • how i pick 4 into string. it should be any number. but the number will be the same. ex in start it is 90 then all group it wil be the 90 Commented Apr 3, 2014 at 5:13
  • check jsfiddle.net/LX3kZ Commented Apr 3, 2014 at 5:17
  • not a fan of modifying html content using string operations... so here you go - jsfiddle.net/arunpjohny/547Pc/1 Commented Apr 3, 2014 at 5:20

1 Answer 1

4

Do this:

var result = 'string'.replace(/\d+(?=\]")/g, function (match) {
    var newNum = Number(match) + 1; // 5
    return newNum;
});
console.log(result);// replaced second number in array with +1

Demo:http://jsfiddle.net/AmitJoki/q9vT6/1

Sign up to request clarification or add additional context in comments.

7 Comments

is it work on all group? i want to chagne all second array element number with +1
@reena.sharam, check out the demo. Paste your html there and click the button
let me try this. how i console this result?
Yuppi its working . can you please tell me one more thing how i store the value in this case '5' in variable to other user?
you want to save 5 in a variable?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.