If I'm reading it right, your regex has only two items in (), which means that only $1 and $2 have any meaning.
I copied your sample text and went to https://regex101.com/ (note: this is not an endorsement) to try to assemble a regex that'll cover all your images. Here's what I ended up with:
Where am I going wrong?
Actually, your code is just fine.
Except that I would simply use wp_generate_password() to generate the random string. :)
WordPress will still think that the scaled version is called
painting-scaled.jpg , etc. Resulting in broken images.
Yes, that's correct.
Images are stored as posts of the attachment type in the WordPress posts ...
Upon debugging we found the wp_max_upload_size function was returning 1MB. The u_bytes and p_bytes were as expected and equal to 100MB as defined in our uploads.ini file but the application of upload_size_limit filter changed the size to 1MB i.e., the problem was at:
return apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
The answer @robbert is a great, great answer. However, it's a little dated (I'm using WordPress 5.7) and I wanted to do this exact same thing, so here's a slightly updated answer with a few extras:
I've used the slug size rather than the dimensions because this is a little cleaner and wanted to demonstrate it from the @robbert code.
An extra filter for ...