SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2001
    Location
    D¨n ╔ideann, Alba
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone know of a regular expression that would allow me to strip the path from the location.pathname of a web page?

    Cheers. Scot-Bot.

  2. #2
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup, here you go:
    Code:
    <script language="JavaScript">
    var re = new RegExp('/', 'i');
    var str = location.pathname;
    var prevStr = '';
    alert(re.test(str));
    /* perform the Reg. Exp. once to remove the initial / from the pathname, which would be like /foo/bar */
    re.exec(str);
    str = RegExp.rightContext;
    do {
    	re.exec(str);
    	str = RegExp.rightContext;
    	prevStr += ('/' + RegExp.leftContext);
    } while (re.test(str) == true);
    alert(prevStr);
    </script>

  3. #3
    SitePoint Member
    Join Date
    Dec 2000
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I should probably note that those alerts are only there for me to test the script, and also for you to see what exactly it was returning. You can deal with them as you please :-) Hope I helped!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •