title: Can this Regex be optimized?
body: <p>I need to match the following patterns:</p>
  
  <pre><code>#/a/b/c/d
  #/a/b/&amp;1/d
  #/a/b/c[&amp;1]/d
  </code></pre>
  
  <p>The following rules apply:</p>
  
  <pre><code>a) # is the number sign and then its a path. Pretty much anything can be in the path segments. For &amp;1 and []'s, they follow certain rules.
  b) &amp;1 (or any number) has to be in a path segment by itself
  c) [&amp;1] has to follow at least one character and has to end the segment, only [&amp;l1] is allowed for now
  </code></pre>
  
  <p>So, I came up with the following:</p>
  
  <pre><code>^#((/[^/&amp;]+)|(/&amp;\\d+)|(/[^/]+\\[&amp;1\\]))+
  </code></pre>
  
  <p>Seems to be working, but my profiler is showing that its a bottleneck. Is there a way to improve performance or restructure it in a more optimized way? I don't need to capture or group anything, I just need to know if its a valid path.</p>