Input string:
<ref> Hi this one to be rmoved} {{sdjfhk arbit shit}} [whatever] </ref> But this one to be preserved. <ref> again this has to be removed. </ref>
Output String:
But this one to be preserved.
i tried: $str = preg_replace('/^<ref.*?ref>$/', '', $str);
You were very close. You just want to drop your
^and$characters.See it working here on tehplayground.com
Side note: Since you’re looking for HTML tags, you should technically be using a DOM parser for this.
PHP Simple HTML DOM Parser is great for this kind fo task 🙂