title: JavaScript RegEx to match url path
body: <p>I have possible url paths as below</p>
  
  <pre><code>/articles
  /payment
  /about
  /articles?page=1
  /articles/hello-world
  </code></pre>
  
  <p>I would like to match only the main path of the url, expected matches: <code>['articles', 'payment', 'about', 'articles', 'articles']</code></p>
  
  <p>So I tried to construct the JavaScript <a href="https://regex101.com/r/quuH30/1" rel="nofollow noreferrer">RegEx</a> and came up with as nearest as I can <code>[a-z].*(?=\/|\?)</code>, unfortunately it only matches string inside the last two</p>
  
  <p>Please guide
  Thanks everyone</p>