Regex, Match uppercase characters not between brackets

时间秒杀一切 提交于 2020-01-16 18:48:12

问题


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



来源:https://stackoverflow.com/questions/25711903/regex-match-uppercase-characters-not-between-brackets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!