Adding span tags to post titles using regex

It’s nice to use regex, but you can also achieve the same thing here by just splitting the string on ':' with explode e.g.:

    $matches = explode(":", get_the_title()) ;

    if (count($matches) == 2) {
       $result = "foo bar $matches[0] foo bar $matches[1]";
    } else {
       // case with no : in title
       $result = "foo bar $matches[0] foo bar";
    }
    echo $result;