Insert a field with PREG_REPLACE – strange behaviour

You need to use get_field function here instead of the_field.

function wrapImagesInDiv($content) {
    if ( in_category( 'projects' ) ) {
        $pattern = '/(<img[^>]*class=\"([^>]*?)\"[^>]*>)/i';
        $replacement="
        <div class="owl-wrapper">
            <div class="owl-item $2">
                ".get_field('description').'
                $1
            </div>
        </div>';
        $content = preg_replace($pattern, $replacement, $content);
    }
    return $content;
}
add_filter('the_content', 'wrapImagesInDiv');

Function get_field returns the value but the_field prints the value.