fork(1) download
  1. import re
  2. text = "Some example text (SET) that demonstrates what I'm looking for. Energy system models (ESM) are used to find specific optima (SCO). Some say computer systems (CUST) are cool. In the summer playing outside (OUTS) should be preferred."
  3. print( [x.group() for x in re.finditer(r'\b([A-Z])\w*(?:\s+\w+)*?\s*\(\1[A-Z]*\)', text, re.I)] )
Success #stdin #stdout 0.02s 9712KB
stdin
Standard input is empty
stdout
['Some example text (SET)', 'Energy system models (ESM)', 'specific optima (SCO)', 'computer systems (CUST)', 'outside (OUTS)']