Regex match everything between two {}

橙三吉。 提交于 2019-12-05 17:02:20

See regex in use here

(?<=(?<!@)\{)[^}]*(?=})
  • (?<=(?<!@)\{) Positive lookbehind ensuring what precedes matches the following
    • (?<!@) Negative lookbehind ensuring what precedes doesn't match @ literally
    • \{ Match { literally.
  • [^}]* Matches any character except } any number of times
  • (?=}) Positive lookahead ensuring what follows is } literally

Results:

{eww}           # Matches eww
r23r23{fetwe}   # Matches fetwe
#{d2dded}       # Matches d2dded
@{d2dded}       # Does not match this because @ precedes {

Use this regex:

(?<!@\{)(?<=\{).*?(?=\})

A negative lookbehind to assure no @{, a positive lookbehind to assure a { and a positive lookahead to assure a }.

Try it online here.

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