^data:((?:\w+\/(?:(?!;).)+)?)((?:;[\w\W]*?[^;])*),(.+)$
test this pattern on regexr: https://regexr.com/4inht
regex pattern to match RFC 2397 data URL
dataurl := "data:" [ mediatype ] [ ";base64" ] "," data mediatype := [ type "/" subtype ] *( ";" parameter ) data := *urlchar parameter := attribute "=" value
data:image/jpeg;base64,UEsDBBQAAAAI
data:image/jpeg;key=value;base64,UEsDBBQAAAAI
data:image/jpeg;key=value,UEsDBBQAAAAI
data:;base64;sdfgsdfgsdfasdfa=s,UEsDBBQAAAAI
data:,UEsDBBQAAAAI
Maybe I am wrong but from wikipedia (and RFC 2397), base64 should not be before parameters, therefore exemple4 should not validate
https://en.wikipedia.org/wiki/Data_URI_scheme
Here is the regex I figured out : https://regex101.com/r/6DOoB1/1
The same regex but with a short list of tests : https://regexr.com/5lf3v