Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
PCRE (PHP <7.3)

/
^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{2}={2})$
/
gm

Description

This regex will match on Base64 strings (not hard-wrapped). It was designed to match on a string that is MOD4 with appropriate padding.

Keep in mind, this is very basic. You will likely need to add before and after anchors to meet your needs.

Submitted by Damian Torres - 8 years ago