Search code examples
regexpcrebbedit

RegEx to remove text not inside parentheses


How can I remove text that is not in between parentheses? This Regex101 selects text inside of parentheses. I'm using BBEdit and the PCRE engine.

Convert:

AFGHANISTAN (AF)
LAND ISLANDS (AX)
ALBANIA (AL)
ALGERIA (DZ)
AMERICAN SAMOA (AS)
ANDORRA (AD)
ANGOLA (AO)

To:

(AF)
(AX)
(AL)
(DZ)
(AS)
(AD)
(AO)

Solution

  • Use this:

    .*?(\([^)]*\))
    

    and replace with $1

    Demo & explanation