想知道这是否可能
$c = "The color {{ white }} will become {{ white }}.";
$c = preg_replace("#{{\s*white\s*}}#", "black", $c);
结果将是
The color black will become black.
如果附加了{和}或任何其他字符,是否有办法忽略它,所以
$c = "The color {{{ white }}} will become {{ white }}.";
将成为
The color {{ white }} will become black.
谢谢。
答案 0 :(得分:4)
答案 1 :(得分:0)
试试这个正则表达式/\{{2,3}\s*white\s*\}{2,3}/
。这是你的例子。
$c = "The color {{{ white }}} will become {{ white }}.";
echo preg_replace("/\{{2,3}\s*white\s*\}{2,3}/", "black", $c);
\{
和\}
表示括号。并且{2,3}
表示它应该匹配2或3个括号。