Regular Expressions 101

Community Patterns

1...34567...884

PGP-encrypted message

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, valid headers, and checksum.

Submitted by Adroit - 3 months ago