[thelist] Testing URL with regular expression

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Thu Oct 13 09:32:23 CDT 2005


Did not quite understand your conditional but the following regular
expression matches what you need imho;

/URL\/(index\.php)?(#anchor)?/

tested with

  "URL/"
  "URL/index.php"
  "URL/#anchor"
  "URL/index.php#anchor"

Explanation:

/URL\/(index.php)?(#anchor)?/

1. Match characters "URL/"
2. Match "index.php" zero or one times
3. Match "#anchor" zero or one times

I may consider googling "javascript regular expressions" before
jumping straight into the project. There are excellent tutorials out
there.

HTH,
Volkan.


2005/10/13, Gardiner, Iain <Iain.Gardiner at inbev.co.uk>:
> 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
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>


--
Volkan Ozcelik
+>Yep! I'm blogging! : http://www.volkanozcelik.com/volkanozcelik/blog/
+> My projects/studies/trials/errors : http://www.sarmal.com/


More information about the thelist mailing list