Just use the the_title
filter to hook into the title content and work with that.
add_filter( 'the_title', function( $title ) {
// Manipulate the $title as you want and then return that.
// You can add test conditions such as 'is_main_query'
// (https://codex.wordpress.org/Function_Reference/is_main_query)
return $title;
} );