5

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!!!

3 Answers 3

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

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

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

2 Comments

my problem is that 5 and 3 are set dynamically... so I actually need to replace the substring that starts from "false" and till the end of the string...
str = str.substring( 0, str.indexOf( "false" )+5 );
3
str = str.replace(/clicked=[^&]*/, 'clicked=true');

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

Comments

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

Comments

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.