Regular Expressions 101

Community Patterns

Validate Base64 with new lines (e.g. GPG base64 messages)

3

Regular Expression
PCRE (PHP <7.3)

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

Description

This regular expression validates if given string is formatted in Base64, additional it accepts new lines, since payload can have new lines in it.

Submitted by wpodgorski - 9 years ago