-1

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.

Minh Nguyen
  • 1,909
  • 3
  • 16
  • 30

2 Answers2

1

Try this:

\{\{(.*?)\}\}

Using ? will cause the match to stop at the first closing bracket.

Demo here:

Regex101

Tim Biegeleisen
  • 451,927
  • 24
  • 239
  • 318
0

You probably want to use capturing brackets around the text inside the tags. This will return the captured text.

"\{\{([^{}]+)\}\}"

Example here.

Edit: Updated to OP's requirements.

Extragorey
  • 1,535
  • 11
  • 28