Data & Formatting · In-Browser Regular Expression Lab
Base64 Regex — Validate Base64 Strings with Valid Padding
Validates Base64 encoded data with proper 4-character padding multiples using = characters.
Flags:
//none
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:SGVsbG8gV29ybGQ=
Test Samples Verification Matrix
Expected Valid Samples (Should Match)
SGVsbG8gV29ybGQ= Pass
Y2FzdG92 Pass
YW55IGNhcm5hbCBwbGVhc3VyZS4= Pass
Expected Invalid Samples (Must Reject)
SGVsbG8gV29ybGQ== Rejected (Pass)
Invalid#Characters Rejected (Pass)
SGVsbG8= Accepted (Fail)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
const text = "SGVsbG8gV29ybGQ=";
const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);
if (isMatch) {
const matches = text.match(pattern);
console.log("Matches:", matches);
}Regular Expression Token Breakdown
Ensures string length is divisible by 4 and valid Base64 alphabet is followed with legal padding. Each component of the regular expression serves a distinct syntactical purpose as mapped below:
| Token Pattern | Name / Component | Function & Rule |
|---|---|---|
| [A-Za-z0-9+/]{4} | Full 4-byte chunk | Standard Base64 alphabet. |
| [A-Za-z0-9+/]{2}== | 2-pad end | Valid ending with 2 padding equals. |
| [A-Za-z0-9+/]{3}= | 1-pad end | Valid ending with 1 padding equal. |
Frequently Asked Questions
What about Base64URL?
Related Regular Expressions
Browse All 40 PatternsAuthentication & Security
JSON Web Token (JWT)
Validates standard 3-part JSON Web Tokens (Header.Payload.Signature) in Base64URL encoding.
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/Test regex
Authentication & Security
MD5 Hash Checksum
Matches 32-character hexadecimal MD5 hash checksum strings.
/^[a-fA-F0-9]{32}$/Test regex
Authentication & Security
SHA-256 Hash Checksum
Matches 64-character hexadecimal SHA-256 cryptographic digest strings.
/^[a-fA-F0-9]{64}$/Test regex