Gaedrida
Gaedrida

Reputation: 1

Regex, Match uppercase characters not between brackets

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}

Upvotes: 0

Views: 185

Answers (3)

alpha bravo
alpha bravo

Reputation: 7948

try this pattern

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

Demo

Upvotes: 1

Avinash Raj
Avinash Raj

Reputation: 174786

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

Upvotes: 1

walid toumi
walid toumi

Reputation: 2282

Try this pattern:

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

Then test group1 if not empty

Demo

Upvotes: 0

Related Questions