title: Simple Bread Crumb with regex
body: <p>I am trying to create a simple bread crumb with regex by splitting a given URL:</p>
  
  <p>Input is a URL in this form - <a href="http://someurl.com:1000/sites/Site1/Pages/Programs/Programs1/Programs2/SomePage.aspx?a=b;c=d" rel="nofollow">http://someurl.com:1000/sites/Site1/Pages/Programs/Programs1/Programs2/SomePage.aspx?a=b;c=d</a></p>
  
  <p>Output expected is - 
  You are here: sites>Site1>Pages>Programs>Programs1>Programs2>SomePage</p>
  
  <p>And here is the code I have used:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
  var url ="http://someurl:1000/sites/Site1/Pages/Programs/Programs1/Programs2/SomePage.aspx?a=b;c=d"
  
  
  var newURL = url.replace(new RegExp( "^(?:([^:/?#]+):)?(?://((?:(([^:@]*):?([^:@]*))?@)?([^:/?#]*)(?::(\\d*))?))?((((?:[^?#/]*/)*)([^?#]*))(?:\\?([^#]*))?(?:#(.*))?)", "g"),
  
    function( $0, $1, $2, $3, $4, $5, $6, $7, $8, $9){
  
    var domain = $1+ "://" + $2;
    var href = domain;
    var urlStrippedDown = $9;
  
    //Split the folders/pages within the path     /sites/Site1/Pages/Programs/Programs1/Programs2/SomePage.aspx
    var pieces = urlStrippedDown.replace( new RegExp (\\w+.aspx)|(\\w+),
  
  
    //Form the bread crumb with anchor tags and text
    function ($0, $1, $2)
    {
  
      zero = $0;
      var test =  "&lt;a href='" + href +     urlStrippedDown.substring(0,urlStrippedDown.indexOf($0)+$0.length) +"'&gt;" +     zero.replace('.aspx','')  + "&lt;/a&gt;";
      return test;
    }
    );
  
    return pieces;
    }
  );
  
  
  //document.write("You are here: " + newURL.replace(/\//g,''));
  document.write("You are here: " + newURL);
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Problem faced:
  The only issue I am facing is that the final output (newURL) has a forward slash ("/") between each link, that I would like to replace with ">" but this seems to be impossible. I am not sure how this "/" is getting inserted, though its not showing it as part of text when the "anchor" tag is formed.</p>
  
  <p>The expected output is- You are here: sites>Site1>Pages>Programs>Programs1>Programs2>SomePage  </p>
  
  <p>whereas I get- You are here: /sites/Site1/Pages/Programs/Programs1/Programs2/SomePage 
  and I am unable to replace this "/" with ">"</p>
  
  <p>P.S: The commented line of code - If I replace here, it replaces all "/" even those inside the anchor tags. The "/" should be replaced in the text and not in the href of the anchor</p>
  
  <p>Is there a flaw in the regex? Are there better ways to handle this? </p>
  
  <p>Thanks!</p>