0

I don't understand why it is giving me false while the two strings are equal.

var str = 'https:\/\/monsite.com\/"onload="alert(1)"';
var patt = /https:\/\/monsite.com\/"onload="alert(1)"/i;
var result = patt.test(str);
document.write("Returned value: " + result);

I am a new beginner.

2
  • 2
    It could be the parentheses in your regex. Commented Mar 30, 2013 at 16:49
  • 2
    @kirowaxoaw, yes you do, surrounding the number 1. Commented Mar 30, 2013 at 16:51

1 Answer 1

6

You need to escape parentheses inside Regex they are special characters.

/https:\/\/monsite.com\/"onload="alert\(1\)"/
Sign up to request clarification or add additional context in comments.

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.