Text Processingflags: g

Base64 String

Match Base64-encoded strings, including proper padding with = and == characters.

Try it in RegexPro →

Available in

JavaScript / ECMAScript code

jsJavaScript
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).

Pattern

regexengine-agnostic
(?:[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

The pattern matches groups of 4 Base64 characters ((?:[A-Za-z0-9+\/]{4})*) then allows the trailing partial group: 3 chars + one =, or 2 chars + ==. This enforces valid Base64 padding rules.

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