Qaynaq LABS · TOOLS

REGEX · PYTHON

Regex explained

^[A-Za-z0-9+/]{86}={0,2}$

Matches a string of exactly 86 URL-safe Base64 characters followed by zero, one, or two padding '=' characters, ensuring the string is exactly 86 or 88 characters long.

Token-by-token breakdown

TokenMeaningExample
^ Anchor: asserts position at start of the string Start of string
[A-Za-z0-9+/] Character class: matches any uppercase letter, lowercase letter, digit, '+', or '/' A, z, 5, +, /
{86} Quantifier: exactly 86 occurrences of the preceding character class 86 characters from the class
= Literal character: matches the '=' character =
{0,2} Quantifier: between 0 and 2 occurrences of the preceding '=' 0, 1, or 2 '=' characters
$ Anchor: asserts position at end of the string End of string

Matches

  • ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
  • ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/==
  • ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=

Does not match

  • ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+
  • ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/===
  • ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/=A
  • ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789/+A

Common pitfalls

  • Assuming the pattern matches Base64 strings of any length (it strictly requires 86 characters before padding).
  • Forgetting that the padding '=' characters must appear only at the end of the string.
  • Confusing this with standard Base64 which may have different padding rules or character sets.

Performance notes

The pattern is efficient as it uses fixed quantifiers and a simple character class. No catastrophic backtracking risk due to the absence of nested quantifiers or alternations.

About regular expressions

Regular expressions are tiny programs that match patterns in text. They're powerful and notoriously cryptic — most engineers can write them but few can read them confidently. Qaynaq Labs' regex explainer breaks any pattern into its constituent tokens, shows what each one does, and runs through both matching and non-matching examples so you can verify the logic.

Different regex flavors (JavaScript, PCRE, Python, Go) have subtle differences in syntax and supported features. Pick your flavor in the input — the explainer accounts for it.

Frequently asked

Does this pattern match all valid Base64 strings of length 86 or 88?

No. It only matches Base64 strings that use the URL-safe character set (A-Za-z0-9+/) and allows 0-2 padding '=' characters at the end. Standard Base64 may use different characters or padding rules.

Can this pattern match strings shorter than 86 characters?

No. The {86} quantifier requires exactly 86 characters from the character class before any padding.