negate and repeat a atomic group in javascript regex -


i need

  • match {{
  • start capture group
  • anything thats not }}
  • end capture
  • match }}

sample:

dummy text {{ text matched }} more dummy text dummy dummy {{ foo { bar }} dummy text dummy text {{}}} 

result:

match 1: {{ text matched }}

group 0: text matched

match 2: {{ foo { bar }}

group 0:foo { bar

match 3: {{}}}

group 0: }

the problem i'm having not }} part since javascript not have atomic groups.

i cannot negate non-capturing group , repeat this

{{                  match {{     (               capture         ^(?:}})+    not "}}" 1+ times      )               end capture }}                  match }} 

this/{{(.+)}}/ kinda works if don't have line breaks.

to fit requirement, can use pattern:

{{([^}]*(?:}[^}]+)*}*)}} 

details:

{{ (     [^}]*         # not closing bracket     (?:         }[^}]+    # closing bracket followed @ least 1 other character     )*     }*            # eventual closing brackets @ end ) }} 

an other way (shorter less efficient):

{{([^]*?)}}(?!}) 

note: problem has nothing atomic groups.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -