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 matchedmatch 2:
{{ foo { bar }}group 0:
foo { barmatch 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
Post a Comment