SELECT raw.code --,raw.url ,x.seq ,mold.code[1] ,mold.seq ,x.img[1] img FROM scrape.raw LEFT JOIN LATERAL REGEXP_MATCHES(html, $$background-image: url\((.*?(.jpg))$$::TEXT,'g') WITH ORDINALITY AS x(img, seq) ON TRUE LEFT JOIN LATERAL regexp_matches(x.img[1],$$([A-Z,\.,0-9]{7,8}).*\.jpg$$) WITH ORDINALITY AS mold(code, seq) ON TRUE