Two fairly basic questions:
I need to supply a method with an array of strings, which will
eventually be used to pattern match against another array of strings.
1. Is there a good way to span multiple lines when creating an array
from a list of strings? (I want the most readable list I can get.)
// The following doesn't seem to work
urlExclusions = newArray(
"my.domain. com/dir1",
"another.domain .com/dir2",
"third.domain.c om/blah"
);
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(urlExclu sions[i], "i") do all the necessary escaping of
whatever literals might be in the urlExclusions[i] string? (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.l ength; i++) {
pattern = new RegExp(urlExclu sions[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.
Thanks,
Jamie
I need to supply a method with an array of strings, which will
eventually be used to pattern match against another array of strings.
1. Is there a good way to span multiple lines when creating an array
from a list of strings? (I want the most readable list I can get.)
// The following doesn't seem to work
urlExclusions = newArray(
"my.domain. com/dir1",
"another.domain .com/dir2",
"third.domain.c om/blah"
);
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(urlExclu sions[i], "i") do all the necessary escaping of
whatever literals might be in the urlExclusions[i] string? (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.l ength; i++) {
pattern = new RegExp(urlExclu sions[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.
Thanks,
Jamie
Comment