I need to create a regular expression that is able to determine //example or //www.example in the website URL . I get the url location of website by ,
var urlOfWeb = location.href ;
I created a regular expression in JavaScript which gives an irregular output when run multiple times . I tried it in firefox browser / console / Phpstorm IDE . Here is the expression ,
// The regular expression
var expToLookFor = /(\/\/example|\/\/www\.example)/g;
// Using test method of Regexp object of javascript which gives bool result
expToLookFor.test("//example") ;
// Result : true
expToLookFor.test("//example") ;
// Result : false

gflag in your regular expression./\/\/(?:www\.)?example/