[Javascript] parse question

Nick Fitzsimons nick at nickfitz.co.uk
Mon Feb 26 08:21:15 CST 2007


On 26 Feb 2007, at 14:03:49, Mike Dougherty wrote:

> On Mon, 26 Feb 2007 08:01:07 +0100
>  Emmanuel <emmanuel at quomodo.com> wrote:
>> var s = "http://www.mydomain.com/firstdir/secondir/myfile.txt";
>> s = s.replace ( /.*\// , "" )
>
> fwiw:  you might actually need to do something else with the source  
> string, so maybe this:
>
> var s = "http://www.mydomain.com/firstdir/secondir/myfile.txt";
> var f = s.replace ( /.*\// , "" );
>
> ...would be more conservative?

Particularly if (as seems likely) the original value is being  
retrieved from location.href:

self.location.href = self.location.href.replace(/.*\//, "");

is unlikely to have the desired effect :-)

Cheers,

Nick.
-- 
Nick Fitzsimons
http://www.nickfitz.co.uk/






More information about the Javascript mailing list