Search code examples
regexregex-lookaroundsregex-group

Regex Expression for capturing a starting and ending with a group of characters


I've been looking for an answer for quite a while, and i can't find it anywhere else, so I'm posting over here. I need a regex for capturing this form of expression {{{any_Name}}}. I'm looking towards capturing the starting 3 {{{ and the ending 3 }}}.

I can capture the first three with the expression \{{3}/g. But i can't figure out how to catch the last 3 }}}


Solution

  • Try this:

    \{{3}[^{}]+}{3}
    

    See live demo.

    This matches:

    • \{{3} is {{{
    • [^{}]+ is "one or more non-brackets"
    • }{3} is }}}

    Note that } does not need escaping.