preg_replace for a word ending with a colon

php

Solution

`preg_replace` regexes need to be delimited. So, first, try encasing your regex in slashes. Second, I don't understand your regex. Something simple like `/(\w+):/` should work.

preg_replace("/(\w+):/", "<br><br><b>$1</b><br>", $text);

@AndiLeeDavis Edited answer to handle multi-word titles and get rid of extraneous breaks at the beginning:

$mtext = preg_replace("/\.?\s*([^\.]+):/", "<br><br><b>$1</b><br>", $text);
if (strcmp(substr($mtext, 0, 8), "<br><br>") == 0) $mtext = substr($mtext, 8);

Problem

I've tried looking into preg_replace, except that I have not much experience with regular expressions. What I'm trying to do is replace a portion of text ending with a colon and make it bold and put a line break in before and 2 line breaks after. IE convert this text ``` title1: is some text here. title2: another piece of text. ``` to ``` **title1:** is some text here. **title2:** another piece of text ``` I've tried doing something like this... ``` preg_replace("!\*(.*?)\*!$:","\<br \/\>\<strong\>!\*(.*?)\*!\<\/strong\>\<br \/\>",$text); ``` I can't seem to get it to work. Can anyone help? Thanks Andi

Original source