0

After a series of searching, maybe it's time for some help. How can i write a (PHP) regex to extract the string inside brackets:

This is a string with some {{variable1}}, {{variable2}}, and {{variable3}} inside.

Output:

variable1 or {{variable1}}
variable2 or {{variable2}}
variable3 or {{variable3}}

As long as we can extract the variables.

Thank you and any help will be appreciated.

user1240207
  • 217
  • 1
  • 3
  • 13
  • 1
    @zx81 why can't you post it on the older question? – i3arnon Jun 27 '14 at 03:04
  • 1
    @I3arnon Posted [new answer here](http://stackoverflow.com/a/24443390/1078583). Thanks for the suggestion, that hadn't arisen to me. :) – zx81 Jun 27 '14 at 03:25

1 Answers1

0

The problem you are facing is (probably) that brackets "mean" something in regexes. So you need to escape them, either with \ (which needs to be doubled) or by putting them in classes [].

/\\{\\{([^}]+)\\}\\}/g

should do the trick, I believe.

jcaron
  • 17,302
  • 6
  • 32
  • 46