← GalleryPemFormatRegex2023✨ Emoji Combos/(-----BEGIN PUBLIC KEY-----)(?:\r|\n|\r\n)((?:(?:(?:[A-Za-z0-9+\/]{4}){16}(?:\r|\n|\r\n))+)(?:(?:[A-Za-z0-9+\/]{4}){0,15})(?:(?:[A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)))(?:\r|\n|\r\n)(-----END PUBLIC KEY-----)|(-----BEGIN PRIVATE KEY-----)(?:\r|\n|\r\n)((?:(?:(?:[A-Za-z0-9+\/]{4}){16}(?:\r|\n|\r\n))+)(?:(?:[A-Za-z0-9+\/]{4}){0,15})(?:(?:[A-Za-z0-9+\/]{4}|[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)))(?:\r|\n|\r\n)(-----END PRIVATE KEY-----)/mgPCRE2+03 years ago✓ Pre-loaded
About this regex
Matches complete PEM-encoded public or private key blocks, including the BEGIN/END header/footer lines and the base64 body wrapped in 64-character lines with proper = or == padding. Supports
,
, or
line endings and captures the header and body separately. Useful for extracting or validating cryptographic keys embedded in logs, configs, certificates, or other text.