Regular Expressions 101

Community Patterns

Identify and group Certificate and Private Key from a combination PEM file

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(?ms)(\s*((?<privatekey>-----BEGIN .* PRIVATE KEY-----.*?-----END .* PRIVATE KEY-----)|(?<certificate>-----BEGIN CERTIFICATE-----.*?-----END CERTIFICATE-----))\s*){2}
/
gm

Description

Identify and group Certificate and Private Key from a combination PEM file

Submitted by @rbleattler - a year ago