title: How do I make part of a regex match optional?
body: <p>This is an example string:</p>
  
  <pre><code>123456#p654321
  </code></pre>
  
  <p>Currently, I am using this match to capture <code>123456</code> and <code>654321</code> in to two different groups:</p>
  
  <pre><code>([0-9].*)#p([0-9].*)
  </code></pre>
  
  <p>But on occasions, the <code>#p654321</code> part of the string will not be there, so I will only want to capture the first group. I tried to make the second group "optional" by appending <code>?</code> to it, which works, but only as long as there is a <code>#p</code> at the end of the remaining string.</p>
  
  <p>What would be the best way to solve this problem?</p>