[thelist] [ColdFusion] Regular Expression Questions

Beam sbeam at syxyz.net
Tue Feb 25 08:24:01 CST 2003


> <jeff at members.evolt.org> wrote:
> > so, next question is how to find relative and root relative links in
> > the document.  obviously, '<a href="(\/?[^"]+)' is far too general.
>
> I think you can get away with this:
>
> <a href="([^:"]+)"
>
> All absolute URLs have colons in them between the protocol and the rest
> of the URL AFAIK (https?:, ftp:, mailto:), and so a URL that is lacking
> them would be relative.
>

well, you could have a : in the path somewhere, so you could either say:
^(https?|ftp|mailto):\/\//
where anything that does NOT match is a relative link, or,
^(\/?(\.\.?\/)*)
which is sexier and matches things like
/foo/bar
./foo/bar
../../../foo/bar
but also
/////wtf



More information about the thelist mailing list