Reputation: 685
i have a string as abcsd[2].asdwdw[3].asdsds
. I need to find and replace digit 3 with other.
i have tried some but they only replace the first or all digits in the string.
Upvotes: 0
Views: 93
Reputation: 388416
Try
var x = 'abcsd[2].asdwdw[3].asdsds';
var newvalue = 5;
var y = x.replace(/(.*?\..*\[)\d+/, '$1' + newvalue)
Upvotes: 1