Combining two groups into one in regex
<p>I am parsing IBM JVM thread dumps to extract various information. In current context the lock id on which the thread is waiting, and the id of the thread owning that lock. The lock id is consistent across all dumps and it takes form of hex value <code>0x000000000B0D9A20</code>. But id of thread holding lock takes different values like hex id of the same form as lock id or something like <code>&lt;unknown&gt;</code> or <code>&lt;unowned&gt;</code>. It is lock owner's id that I am finding difficult to extract.</p>

<p>IBM thread dump specifies lock info with three clauses (as you can see in first screenshot):</p>

<ol>
<li><code>Waiting on...</code></li>
<li><code>Blocked on...</code></li>
<li><code>Parked on...</code></li>
</ol>

<p>I am performing OR operation on these clauses in regex. </p>

<p>I have written a generic method which accepts </p>

<ol>
<li>thread dump line</li>
<li>regex to apply</li>
<li>Number of groups to return in a list </li>
</ol>

<p>For example the call <code>method1(threadDumpLine,regex,2)</code> will apply <code>regex</code> on <code>threadDumpLine</code> and return the list <code>[group1,group2]</code> where <code>group1</code> is a 1st group captured while <code>group2</code> is 2nd one. </p>

<p>The first group need to be the lock id, which I am able to capture but second group can be either hex id or <code>&lt;unknown&gt;</code> or <code>&lt;unowned&gt;</code>. I am able to capture lock owner's id as 2nd group, but when it is <code>&lt;unowned&gt;</code> or <code>&lt;unknown&gt;</code> then it turns out to be 3rd group:</p>

<p><a href="https://i.stack.imgur.com/TtlRa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TtlRa.png" alt="enter image description here"></a>
(above on <a href="https://www.regex101.com/r/pV3vV0/1" rel="nofollow noreferrer">regex101</a>)</p>

<p>That was happening because I defined two separate groups to capture lock owner's id and <code>&lt;text&gt;</code>. So I tried to combine the two in one as follows:</p>

<p><a href="https://i.stack.imgur.com/CHyxu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CHyxu.png" alt="enter image description here"></a>
(above on <a href="https://www.regex101.com/r/uW8dW1/2" rel="nofollow noreferrer">regex101</a>)</p>

<p>How can I change the regex to capture as specified above with least possible steps?</p>