^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
One should perhaps also be humble to admit that one can have own bugs; I would second that example #4 is wrong:
data:;base64;sdfgsdfgsdfasdfa=s,UEsDBBQAAAAI
is not valid afaik.The reason for me saying so is that if you look at the standard you posted, you see that:
attribute = value
is a parametertype / subtype
as part ofmedia-type
media-type
is always placed before";base64"
A valid example according to these statements would be:
data:;sdfgsdfgsdfasdfa=s;base64,UEsDBBQAAAAI
I may of course be wrong.. 👍