Base64 String
Match Base64-encoded strings, including proper padding with = and == characters.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("(?:[A-Za-z0-9+\\/]{4})*(?:[A-Za-z0-9+\\/]{2}==|[A-Za-z0-9+\\/]{3}=)?", "g");
const input = "SGVsbG8gV29ybGQ=";
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
import re
pattern = re.compile(r"(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?")
input_text = "SGVsbG8gV29ybGQ="
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
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?`)
input := `SGVsbG8gV29ybGQ=`
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
(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)? (flags: g)Raw source: (?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?
How it works
Examples
Input
SGVsbG8gV29ybGQ=Matches
SGVsbG8gV29ybGQ=
Input
dGVzdA==Matches
dGVzdA==
Input
not!base64!@No match
—Common use cases
- •Detecting Base64 payloads in HTTP bodies or headers
- •Config file secret detection (base64-encoded credentials)
- •Email MIME part extraction
- •JWT payload decoding pipelines
Related patterns
Triple-Quoted String (Python / TS)
Text ProcessingMatch triple-quoted strings (Python docstrings, TypeScript triple-quote, etc.) including newlines.
Hashtag
Text ProcessingMatch hashtags (# followed by word characters) in social media posts, including accented Latin characters.
Python f-String Expression
Text ProcessingMatch `{expression}` placeholders inside Python f-strings (or any single-brace template syntax).
Emoji (Unicode)
Text ProcessingMatch emoji characters across the main Unicode emoji ranges — requires the Unicode flag in JavaScript.