[thelist] Testing URL with regular expression
Gardiner, Iain
Iain.Gardiner at inbev.co.uk
Thu Oct 13 04:56:47 CDT 2005
Morning all,
I'm making my first foray into regular expressions today because I've found
that I need to make a simple test in Javascript. I was wondering if anyone
can give me advice on methodology.
Basically, I want to check the window.location against the href element of
a link but it's important that it can match if the filename and/or anchors
are included. So I've arrived at this expression:
urlRegEx = /(index.php)?(#{1}.*)?/;
And I use this conditional:
if (navigationLink.href == window.location + urlRegEx)
Hopefully this will match all of these eventualities:
URL/
URL/index.php
URL/#anchor
URL/index.php#anchor
I am not in a position to test this out at the moment, but I was hoping
someone could verify or offer advice on how it should be done and how best
to achieve it.
Thanks,
Iain
More information about the thelist
mailing list