Julien
Julien

Reputation: 4183

remove a string with {{ xxx }} inside another string

This is a stupid question but I would like to remove {{Lien web ....}} (including brakets) inside a string.

Example :

test {{Lien web|xyz}} test {{xyz}} test

Result should be :

test test {{xyz}} test

I tried with :

preg_replace('/\{\{.*?\}\}\s*/s','',$string);

but how to add "Lien web" ?

Thanks a lot!

Upvotes: 0

Views: 150

Answers (2)

Dmitry Egorov
Dmitry Egorov

Reputation: 9650

The regex is \{\{Lein web[^\}]*]\}\} and the respective preg_replace:

preg_replace('/\{\{Lien web[^\}]*\}\}/','',$string, -1);

The last -1 replaces all {{Lien web...}} occurrences

Upvotes: 1

Sk93
Sk93

Reputation: 3718

Try:

preg_replace('/\{\{Lien web[^\}]*\}\}/','',$string,-1);

Upvotes: 2

Related Questions