Add attribute only to first image of every post via functions.php

add_filter( 'the_content', 'wpse317670_add_img_attribute' ); 

function wpse317670_add_img_attribute( $content ) { 
    $from = "https://wordpress.stackexchange.com/".preg_quote('<img', "https://wordpress.stackexchange.com/")."https://wordpress.stackexchange.com/";
    $to = '<img example="example"';

    return preg_replace($from, $to, $content, 1);
}

This will add the example="example" to the first image found in every post content.

There is another option, without using regular expression (possibly much faster and will use less memory):

add_filter( 'the_content', 'wpse317670_add_img_attribute' );

function wpse317670_add_img_attribute( $content ) {
    $from = '<img';
    $to   = '<img example="example"';

    $pos = strpos( $content, $from );
    if ( $pos !== false ) {
        return substr_replace( $content, $to, $pos, strlen( $from ) );
    }

    return $content;
}