You could try using several regexps to only search outside angle brackets:
function wpse159789_posts_search( $search, $query ) {
global $wpdb;
if ( ! preg_match( '/wp_posts' . $wpdb->posts . '\.post_content LIKE \'%(.+)%\'/', $search, $matches, PREG_OFFSET_CAPTURE ) ) {
return $search;
}
$q_search$search_str = esc_sql( preg_quote( stripslashes( $matches[1][0] );
) ); // Cater for closed angle pairs embedded in the search string.
$regexsfor ( $i = array0, $len = mb_strlen( $search_str ); $i < $len; $i++ ) {
$regexs[] $q_searches[] = '^''(<[^>]*>)?' . $q_search;preg_quote( mb_substr( $search_str, $i, 1 ) );
$regexs[]}
$q_search = '^[^<]+'implode( .'', $q_search;$q_searches );
$regexs[] = '<[^>]*>''^[^<]*' . $q_search; // Before any angle bracket.
$regexs[] = '<[^>]*>[^<]+''(<[^>]*>)[^<]*' . $q_search;
// After any closed $regexangle =bracket 'wp_postspair.post_content
RLIKE \'' . array_unshift( $regexs, implode( '\'' OR wp_posts', array_fill( 0, count( $regexs ), $wpdb->posts . '.post_content RLIKE \''%s' ) ) );
$search_replace = call_user_func_array( array( $wpdb, $regexs'prepare' ), .$regexs '\'';);
$search = substr( $search, 0, $matches[0][1] ) . $regex$search_replace . substr( $search, $matches[0][1] + strlen( $matches[0][0] ) );
return $search;
}
add_filter( 'posts_search', 'wpse159789_posts_search', 10, 2 );
I'm not sure this covers all cases, but seems to work on limited testing ... (it'd be a lot simpler if MySQL regexp supported look behind/ahead).