Are you trying to match a link which you have mentioned in previous post http://www.webmd.com/search/search_results/default.aspx?query=dizziness%20drowsiness%20lightheadedness%20 or it is a part of some string?
If it is a part of a string can you post a whole string?
"%" character doesn't need to be escaped. "/" character needs to be escaped if you are using following regExp constructor.
var regExp = //
If you don't escape "/" character in your regExp expression JavaScript will assume that you are closing regExp constructor instead of specifying forward slash character to match. Likewise you have to escape "?" character because it is a special RegExp character which says: match the previous item zero or one time.
Some examples:
var string = "http://";
var regExp = /\//g;
var x = string.replace(regExp,"?");
document.write(x)
The output of the above code will be:
http:??
Another example:
var string = "http://www.somewebsite.com/some%20webpage?some_other_page.html"
var regExp = /%20|\?/g
var x = string.replace(regExp,"_");
document.write(x)
The output of the above code will be:
http://www.somewebsite.com/some_webpage_some_other_page.htm
And yet another expample:
var string = "http://www.somewebsite.com"
var regExp = /(http)?:\/\/www.somewebsite.com/g
var x = string.replace(regExp,"x");
document.write(x)
The output of the above code will be:
x
Now if you change above string variable to hold this value:
var string = "ftp://www.somewebsite.com"
The output will be:
ftpx
Why? Because with
var regExp = var regExp = /(http)?:\/\/www.somewebsite.com/
expression you told JavaScript to match the pattern with none or one occurrence of "http" followed by "://www.somewebsite.com". If you omit "?" character in "ftp" case there would be no pattern to match against.
Hope now you understand why you have to escape "?" character or any other special character if it is a part of a string.