serene
serene

Reputation: 685

jquery regular expression replace digit at second index

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

Answers (1)

Arun P Johny
Arun P Johny

Reputation: 388416

Try

var x = 'abcsd[2].asdwdw[3].asdsds';
var newvalue = 5;
var y = x.replace(/(.*?\..*\[)\d+/, '$1' + newvalue)

Upvotes: 1

Related Questions