[H-GEN] Help with Regular Expressions in javascript?

Jason Parker-Burlingham jasonp at panix.com
Mon Oct 6 09:24:56 EDT 2003


[ Humbug *General* list - semi-serious discussions about Humbug and     ]
[ Unix-related topics. Posts from non-subscribed addresses will vanish. ]

"Peter Arnold" <arnoldpj at optushome.com.au> writes:

> I'd like to filter any (eg) .exe .doc .com .pif files based on their
> appearance in the url 1) intermediatly or 2) at the end.
>
> The best I can do is:
> 1) var contraband = /\.(exe|doc|com|pif)/i;
> 2) var contraband = /\.(exe|doc|com|pif)$/i;

Whether or not this works will depend on the vagaries of the regular
expression syntax ECMAScript uses.  You may or may not have to quote
the parentheses and possibly even the pipes; it's hard to say without
a copy of the language reference or a reasonably accessible
interpreter in front of me.

Besides, for such a small job it *may* be simpler to use the
language's built in substring detection function, if there is one
(most languages have one, perhaps called "index" or something like
that).

Store the list of disallowed substrings in an array and loop over it
comparing the current substring against your target string, breaking
out early if it's found.

(By the way, you know that your first match always succeeds whenever
the second one would, right?)

jason
-- 
Baby Pictures:
      http://panix.com/~jasonp?HenryGrosvenorParkerBurlingham

--
* This is list (humbug) general handled by majordomo at lists.humbug.org.au .
* Postings to this list are only accepted from subscribed addresses of
* lists 'general' or 'general-post'.  See http://www.humbug.org.au/



More information about the General mailing list