Sash
Sash

Reputation: 493

Javascript regex replace function

If I have the following string:

var str = "Test.aspx?ID=11&clicked=false+5+3";
str = str.replace(????????, 'true');

How can I replace the substring "false+5+3" with "true" using REGEX?

Thanks in advance!!!

Upvotes: 5

Views: 666

Answers (3)

tsds
tsds

Reputation: 9030

str = str.replace(/clicked=[^&]*/, 'clicked=true');

this will replace anything in clicked parameter, not only false+...

Upvotes: 3

rdmueller
rdmueller

Reputation: 11042

var str = "Test.aspx?ID=11&clicked=false+5+3";
str = str.replace(/false[+]5[+]3/, 'true');

Upvotes: 0

tskuzzy
tskuzzy

Reputation: 36476

str = str.replace(/false\+5\+3/, 'true');

You need to escape the + since it means something special in regex.

Upvotes: 4

Related Questions