amateur
amateur

Reputation: 44605

Update URL parameter

I have the following string:

http://www.website.com?a=111&b=2222&d=3333

How can I take this string and update the b parameter value with 4444?

Upvotes: 1

Views: 751

Answers (3)

Blazemonger
Blazemonger

Reputation: 92903

String.replace(/b=([^&]*)/, "b=4444")

Upvotes: 1

Aleks G
Aleks G

Reputation: 57316

var str = 'http://www.website.com?a=111&b=2222&d=3333';
str.replace(/([&\?]b=\d+/,"$1b=4444")

Upvotes: 3

Diodeus - James MacFarlane
Diodeus - James MacFarlane

Reputation: 114367

var myString = "http://www.website.com?a=111&b=2222&d=3333".replace("b=2222","b=4444")

Upvotes: -1

Related Questions