I am trying to match everything inside double curly brackets in a string. I am using the following expression:
\{\{.*\}\}
Some examples:
The {{dog}} is not a cat.
This correctly matches {{dog}}
However,The {{dog}} is a {{cat}}
matches everything after the first match instead of returning two matches. I want it to match twice, once for {{dog}} and once for {{cat}}
Does anyone know how to do this?
Thanks.
You have to use non-greedy match:
\{\{.*?\}\}
to match everything between braces, use:
\{\{(.*?)\}\}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With