Problem with regular expression

Hello, I am quite new in php and I have just started using regular expressions. Could anyone help me with this expression? I don’t know why it is not working.

$string = My name is [[Tom]] and I live in [[Germany|Czech republic]];
$pattern = /[[(.*)[^(]])]|/U

$string = preg_replace("$pattern", “”, $string);
$string = preg_replace("/]/", “”, $string);

echo $string;

I would expect the result to be:
“My name is Tom and I live in Czech republic”
but what I get is “My name is Czech republic”.
The whole part between the first [[ and the sign | is replaced…

I have been fighting with this for hours and didn’t find a solution :frowning:

Thanks for any help

Hi there,

With the [[country|country2]] - if it is general would you always want the first or second one to be selected?

Sponsor our Newsletter | Privacy Policy | Terms of Service