Level 6
Ok I changed '/{{ (\w+) }}/i' to '/{{\s*(\w+)\s*}}/i' and now the page displays master.KEY so it is almost working.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone,
I'm stuck on regex, blah! Ok what I'm trying to do is have language tags (keys) within an article's content, then before the content gets displayed find and replace the keys with Lang::get('master.KEY') the key is wrapped with {{}} within my content I would like to replace the curly brackets.
<li class="content">{!! $article->content) !!}</li>
I was thinking you could do something like:
<li class="content">{!! preg_replace('/{{ (\w+) }}/i', Lang::get('master.${1}'), $article->content) !!}</li>
But this does not work it just shows the content with the {{ KEY }} still in it.
Please or to participate in this conversation.