I try to write regex pattern "\{\{.*\}\}" to match tags "{{...}}". But it alway match all string below:
{{ shortcode('') }} abc {{ shortcode('') }}
Please help me correct pattern to match each tag only, thanks for any help.
I try to write regex pattern "\{\{.*\}\}" to match tags "{{...}}". But it alway match all string below:
{{ shortcode('') }} abc {{ shortcode('') }}
Please help me correct pattern to match each tag only, thanks for any help.
Try this:
\{\{(.*?)\}\}
Using ?
will cause the match to stop at the first closing bracket.
Demo here:
You probably want to use capturing brackets around the text inside the tags. This will return the captured text.
"\{\{([^{}]+)\}\}"
Edit: Updated to OP's requirements.