正则表达式删除不在括号内的文本

RegEx to remove text not inside parentheses

如何删除括号中 而非 的文本? Regex101 选择括号内的文本。我正在使用 BBEdit 和 PCRE 引擎。

转换:

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

收件人:

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

使用这个:

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

并替换为

Demo & explanation

关于List of sovereign states, aside of upper-case letters, there should also appear - and ' characters (example "Cote d'Ivoire" (might also be "Ivory Coast") and "Guinea-Bissau") therefore \w shall rather not be used. I'd go for a bit strict Regex

[A-Z'\- ]+ (\([A-Z'-]{2}\))

上面那个的松散变体是 this one:

.* (\(..\))