I have the following code that checks a URL if it contains a certain pattern:
var url = "https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=regex%20javascript";
var patt = new RegExp('https?:\/\/[^/]+\.google\.[a-z.]+\/((search[?#])|(webhp[?#])|([?#])).*q=');
var check = patt.test(url);
alert(check);
The above regex won't work without using new RegExp(). How do I use the same regex without creating the regex object. For example, something like this (which doesn't seem to work):
var url = "https://www.google.co.uk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=regex%20javascript";
var check = ('https?:\/\/[^/]+\.google\.[a-z.]+\/((search[?#])|(webhp[?#])|([?#])).*q=').test(url);
alert(check);