0

My regex allow for now spin syntax {spin1|spin2}

  $customContent = preg_replace('/(\{)(.*?)(})/', '{#'.$index.'#}', $customContent, 1);

I would like to allow unlimited nested bracket { {spin1|spin2} {blabla1|blabla2} }

Could you help me to fix this regex please ?

I have tried the below solutions. None worked.

/{([^{}]*)}/

/(?<={)[^}]*(?=})/

/(\{(?:\{.*\}|[^\{])*\})/m

/\{(((?>[^\{\}]+)|(?R))*)\}/x

/\{.*?\}/i
SarathMS
  • 539
  • 2
  • 6
  • Check out [Bart's answer](http://stackoverflow.com/a/14952740), [Casimir et Hippolyte's answer](http://stackoverflow.com/a/17845034) is also outstanding... – HamZa Sep 12 '14 at 09:56
  • Hamza thx you but im not expert event i understand a little bit, im gonna read it but not sure i will done it – user3216977 Sep 12 '14 at 10:04
  • Recursive patterns are one of the advanced techniques in regex. If you're still a beginner, you might need to practice and read more about regex and common patterns in general. If you're already a bit familiar with regex, you might read [this article](http://www.rexegg.com/regex-recursion.html). – HamZa Sep 12 '14 at 10:08
  • @user3216977 still i don't understand your question. Check this out http://regex101.com/r/bR2iB6/4 – Avinash Raj Sep 12 '14 at 10:33

1 Answers1

-1

Unlimited nesting bracket, with unlimited depth, not empty content: (JS syntax)

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

DEMO

-- EDIT --

Is this what you meant?

/[^{}]*{\s*([^{}]+)?}?\s*[^{}]*/g

DEMO

trincot
  • 317,000
  • 35
  • 244
  • 286
Davide Rossi
  • 516
  • 2
  • 8