Regex, Match uppercase characters not between brac

2019-09-10 02:56发布

问题:

In RegEx, I search a pattern that selects multiple uppercase characters (more than 1), that are not enclosed by curly braces.

It should match:

ABC
AB
XYZABC

but not:

{ABC}
{AB}
{XYZABC}

回答1:

The below regex would match one or more uppercase letters only if it is not followed by a closing curly } bracket.

^[A-Z]+(?!.*?})$

DEMO

OR

You could use perl regex verbs,

{.*?}(*SKIP)(*F)|[A-Z]+

DEMO



回答2:

try this pattern

[A-Z]+(?![^}{]*})  

Demo



回答3:

Try this pattern:

{.*?}|([A-Z]+)

Then test group1 if not empty

Demo