regex - PHP Regular Expression {{ }} -


i having tough time writing php regular expression preg_match. need match following pattern:

{{anything}} {{{anything}}} 

but easy part. want replace such expressions "" (empty string) if string contains if string contains else, need keep, following strings become valid:

this {{anything}} {{{anything}}} anywhere 

help appreciated :).

just use anchors.

preg_replace('~^\{+[^{}]*\}+$\n?~m', '', $str); 

demo


Comments