Skip to main content
Regexflux

Base64 Encoded String

intermediate

Matches base64 encoded strings.

base64encodingdatavalidation

Pattern

/(?:[A-Za-z0-9+/]{4})+(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?|[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=/g

Try It

0 of 6 strings matched

Explanation

Matches base64 encoding: groups of 4 base64 characters, with optional padding (= or ==) at the end. Validates proper padding alignment.

Test Strings

Matching

  • SGVsbG8gV29ybGQ=
  • dGVzdA==
  • YWJjZGVmZw==

Non-matching

  • !@#$
  • ====
  • <<>>

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /(?:[A-Za-z0-9+\/]{4})+(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?|[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

URL-safe base64

[A-Za-z0-9_-]+

Matches base64url encoding (no + / =)