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
|
|---|