-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,989
  • 3
  • 17
  • 30

2 Answers2

1

Try this:

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

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

Demo here:

Regex101

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
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,654
  • 16
  • 30