title: Regex to get string in URL before optional character
body: <p>I have a URL which may be formatted like this: <a href="http://domain.com/space/all/all/FarmAnimals" rel="nofollow">http://domain.com/space/all/all/FarmAnimals</a></p>
  
  <p>or like this: <a href="http://domain.com/space/all/all/FarmAnimals?param=2" rel="nofollow">http://domain.com/space/all/all/FarmAnimals?param=2</a></p>
  
  <p>What regular expression can I use to return the expression FarmAnimals in both instances?</p>
  
  <p>I am trying this:</p>
  
  <pre><code>var myRegexp = /\.com\/space\/[a-zA-Z0-9]*\/[a-zA-Z0-9]*\/(.*)/;
  var match = myRegexp.exec(topURL);
  var full = match[1];
  </code></pre>
  
  <p>but this only works in the first instance, can someone please provide an example of how to set up this regex with an optional question mark closure?</p>
  
  <p>Thank you very much!</p>