regex power

10 views
Skip to first unread message

Rainer Weikusat

unread,
Apr 14, 2022, 2:52:40 PMApr 14
to
Assuming that $chain holds the text of a usual certificate chain file,
ie, multiple certificates concatenated, the expression

$chain =~ /(.+?-----END CERTIFICATE-----\n)/gs

will return a list of individual certificates. That's equivalent to a
loop like

my (@certs, $cert);

for (split(/\n/, $chain)) {
$cert .= "$_\n";
if ($_ eq '-----END CERTIFICATE-----') {
push(@certs, $cert);
$cert = '';
}
}

without having to spell out any of the mechanics. Pretty close to "Do
what I mean!" :-)
Reply all
Reply to author
Forward
0 new messages