in reply to regex needed: Capture a single entity from two discontiguous parts.

The basic answer is you cannot extract a single entity from two discontiguous parts of a string using a regex alone. If you extracted the bits using regex captures, you'd have to concatentate them together at some point. And as there is no way to write a repeated capture, it's gonna get messy trying when there are a variable number of parts to capture.

Your simplest method, as you mentioned, would be to extract the contents of the parens and then remove the commas.

print "$_ : ", do{ ($_) = m[ \( ( [^)]+ ) \) ]x; tr[,][]d; $_ } for map "($_)", qw[ 1,234 1,234,567 1,234,567,890 ];; (1,234) : 1234 (1,234,567) : 1234567 (1,234,567,890) : 1234567890

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."
  • Comment on Re: regex needed: Capture a single entity from two discontiguous parts.
  • Download Code