Webflags: gi
Data URI
Match base64-encoded data URIs, including the MIME type and the base64 payload.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
jsJavaScript
const re = new RegExp("data:[\\w\\/+\\-.]+(?:;[\\w=\\-]+)*;base64,[A-Za-z0-9+\\/=]+", "gi");
const input = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
pyPython
import re
pattern = re.compile(r"data:[\w\/+\-.]+(?:;[\w=\-]+)*;base64,[A-Za-z0-9+\/=]+", re.IGNORECASE)
input_text = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
Go (RE2) code
goGo
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?i)data:[\w\/+\-.]+(?:;[\w=\-]+)*;base64,[A-Za-z0-9+\/=]+`)
input := `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
regexengine-agnostic
data:[\w\/+\-.]+(?:;[\w=\-]+)*;base64,[A-Za-z0-9+\/=]+ (flags: gi)Raw source: data:[\w\/+\-.]+(?:;[\w=\-]+)*;base64,[A-Za-z0-9+\/=]+
How it works
Starts with data:, then a MIME type (word chars, slashes, plus, hyphen, dot), optional parameters, then ;base64, and the base64 payload (letters, digits, +, /, =).
Examples
Input
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAMatches
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA
Common use cases
- •Inline image extraction from HTML/CSS
- •Bundle size auditing
- •Asset migration tooling
- •Security scanning for embedded payloads
Related patterns
HTTP Content-Type Header
WebParse the value of an HTTP Content-Type header, capturing the media type and optional charset.
CSS rgb() Color
WebMatch CSS rgb() and rgba() color functions, including an optional alpha channel.
HTML Comment
WebMatch HTML comments, including multi-line comments and empty ones.
HTML5 Color Input Value
WebValidate the value of an HTML5 `<input type="color">` — exactly 6 hex digits with leading hash.