I have an regex to replace some input, this is the input
{{number}}-{{$index}}
And i want transform to
result = ["{{number}}", "{{$index}}"]
I trying with this regex ({{).*?(}}) but don't give me what i'm expect
I have an regex to replace some input, this is the input
{{number}}-{{$index}}
And i want transform to
result = ["{{number}}", "{{$index}}"]
I trying with this regex ({{).*?(}}) but don't give me what i'm expect
To extract all {{x}} where x can be any character except { or } you can use the following:
{{[^{}]*}}
{{ Match this literally[^{}]* Match any character except { or } any number of times}} Match this literallySimilarly, the following regex does the same as the previous but allows single { and }, but not double {{ or }}:
{{(?:(?!{{|}}).)*}}
{{ Match this literally(?:(?!{{|}}).)* Match any character any number of times except where {{ or }} exists. This is called a tempered greedy token.}} Match this literallyFor a very slight performance gain, you can substitute each instance of {{ for {{2} and each instance of }} for }{2}.