How to exclude the word “class” from being matched in search?

You might try to use the posts_search filter as elegantly suggested by @Kaiser in the first link you provided. Here is one idea:

function filter_search($sql){
    global $wpdb;
    if( strpos(get_query_var("s"),"lass") !== false AND strpos(get_query_var("s"),"class") === false ){
        $sql .= " AND {$wpdb->posts}.post_title NOT LIKE '%class%'";
        $sql .= " AND {$wpdb->posts}.post_content NOT LIKE '%class%'"; 
    }
    return $sql;
}
add_filter( 'posts_search', 'filter_search');

to check if the search term contains lass and not class and then modify the search query to exclude class.

The change in the SQL will look like this:

Before:

AND (((wp_posts.post_title LIKE '%lass%') OR (wp_posts.post_content LIKE '%lass%'))) 

After:

AND (((wp_posts.post_title LIKE '%lass%') OR (wp_posts.post_content LIKE '%lass%'))) 
AND wp_posts.post_title NOT LIKE '%class%' AND wp_posts.post_content NOT LIKE '%class%'

Update:

You can try

   function filter_search($sql){
        global $wpdb;
        if( strpos(get_query_var("s"),"lass") !== false AND strpos(get_query_var("s"),"class") === false ){
            $sql .= " AND ( {$wpdb->posts}.post_content LIKE 'lass %'"; 
            $sql .= " OR {$wpdb->posts}.post_content LIKE '% lass %'"; 
            $sql .= " OR {$wpdb->posts}.post_content LIKE '% lass' )"; 
        }
        return $sql;
    }
    add_filter( 'posts_search', 'filter_search');

if you want to target the exact word lass in the post content.