-4

I am new to javascript and have not much idea about regular expressions. Please help me in understanding the following code.

var r = new RegExp("^.*?https://www\\.facebook\\.com/servlet/SignOn.*$","i");
var content = "https://www.facebook.com/servlet/SignOn?msg=You+are+not+authorized+to+vie…r+level+of+authority.&cm_sp=TopNav-_-servlet-_-MMM&goto=MembersMainMenu%3F";
console.log(content.search(r));// It gives me 0

But when I change the regex to

var r = new RegExp("^.*?https://www\\.facebook\\.com/servlet/SignOn?msg=.*$","i");
console.log(content.search(r));// It gives me -1 , why??
1
  • There is a star after . in the regex Commented Dec 15, 2016 at 11:49

1 Answer 1

0

n? means n is optional you need n\?

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.