Jamie Jackson wrote:
> 2. When I'm looping over the above array in a method, what's the best
> way to use these as patterns to match? Does "new
> RegExp(urlExclusions[i], "i") do all the necessary escaping of
> whatever literals might be in the urlExclusions[i] string?
No. The first parameter of new RegExp() is a string, that string must
have any characters that have special meaning escaped.
> (All
> characters in the above strings should be treated as a literals. I
> don't intend for that list to be a place to put RegEx.)
>
> Example: I want to do something like this with the list:
>
> for (var i=0; i < urlExclusions.length; i++) {
> pattern = new RegExp(urlExclusions[i], 'i');
> if (pattern.test('http://my.domain.com/dir1')) {
> document.write("Matched");
> } else {
> document.write("Didn't Match);
> }
> }
>
> Any tips are appreciated... I'm a newbie.
You're going to have to identify any characters that have special meaning
to regex and escape them before you can use the text in urlExclusions[i].
You can either do this manually when you populate urlExclusions (assuming
the patterns are in a static array defined by you) or do it at run-time
(if the patterns are retrieved from an untrusted source during script
execution).
--
Grant Wagner <>
comp.lang.javascript FAQ -
http://jibbering.com/faq