Agree this isn’t really a WordPress question.
However, I believe the $1, $2, and $3 refer to the capture groups determined by the (.*?) wildcards. Now, regex is totally voodoo to me so I’m sorry I can’t explain it 100%. However if you look at the $pattern definition:
$pattern = '/<img(.*?)src="https://wordpress.stackexchange.com/questions/66610/(.*?).(bmp"gif|jpeg|jpg|png)"(.*?) \/>/i';
Then $1 is the match immediately following the opening <img
.
$2 is the image’s src
attribute
$3 is probably anything that comes after the src attribute
$4 doesn’t look defined to me