<p>Say you have a string, but you don't know what it contains. And you want to replace all occurences of a particular word or part of a word with a formatted version of the same word.
For example, I have a string that contains "lorem ipsum" and i want to replace the entire word that contains "lo" with "lorem can" so that the end result would be "lorem can ipsum"
but if I put the string "loreal ipsum" through the same function, the result would now be "loreal can ipsum".
Thanks</p>

```
$str = preg_replace('/lo(\w*)/', 'lo$1 can', $str);
```
This replaces "lo" plus any word characters with "lo" + the other characters + " can"
It will also replace "lo" with "lo can" - if you don't want this, change
```
\w*
```
to
```
\w+
```