Ask Your Question

Revision history [back]

The regular expression to remove the starting and ending parts from a certificate PEM string would be:

/-----BEGIN CERTIFICATE-----(.*)-----END CERTIFICATE-----/s

This regular expression matches the starting string -----BEGIN CERTIFICATE-----, followed by any characters (captured using the parentheses and the .* expression), and then the ending string -----END CERTIFICATE-----. The s flag at the end of the regex allows the dot character to match newlines as well.