Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

regex power

11 views
Skip to first unread message

Rainer Weikusat

unread,
Apr 14, 2022, 2:52:40 PM4/14/22
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!" :-)
0 new messages