Regular Expressions 101

Community Patterns

PGP-encrypted message (v2)

1

Regular Expression
ECMAScript (JavaScript)

/
^\s*-----BEGIN PGP MESSAGE-----\s*(?:(?:Charset:.*\n)|(?:Version:.*\n)|(?:Comment:.*\n))*\s*(?:(?:[A-Za-z0-9+\/]{4}\n?)*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=))\n(?:=(?:[A-Za-z0-9+\/]{4}\n?)?)\s*-----END PGP MESSAGE-----\s$
/

Description

A javascript regex for a pgp-encrypted message, including optional armor, headers, and checksum. Feel free to make improvements if you think I'm missing something from the spec: https://www.rfc-editor.org/rfc/rfc4880#section-6.2

Submitted by anonymous - a month ago