具有特殊字符的 CSR 主题摘录
CSR Subject with Special Characters extract
我需要提取 $subj,如下面的代码片段所示,但看起来我的 Regex 没有按预期工作。这实际上与此类似: 但 CSR 中的主题条目不同。我不确定我是否在 %subjinfo
的正则表达式中做了一件好事
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my $subj =
'subject=/O=test~@#$^()_+-=\{}|;':",./<>/OU=test~@#$^()_+-=\{}|;':",./<>/emailAddress=test~@#$^()_+-=\{}|;':",./<>/L=CDE/ST=ABC/C=AU/CN=test~@#$^()_+ -=\{}|;':",./<>';
my %subjinfo = ( $subj =~ m,(\w+)=([^=]*)(?:/|$),g );
print Dumper \%subjinfo;
因此必须给出结果:
$VAR1 = {
'subject' => '',
'L' => 'NYC',
'C' => 'AMER',
'OU' => 'test~@#$^()_+-=\{}|;':",./<>',
'emailAddress' => 'test~@#$^()_+-=\{}|;':",./<>',
'ST' => 'AMER',
'CN' => 'test~@#$^()_+-=\{}|;':",./<>',
'O' => 'test~@#$^()_+-=\{}|;':",./<>'
};
这可能吗?你能建议一下吗?
拆分正则表达式看起来比仅使用正则表达式的解决方案更自然,
use Data::Dumper;
my $subj = q(subject=/O=test~@#$^()_+-=\{}|;':",./<>/OU=test~@#$^()_+-=\{}|;':",./<>/emailAddress=test~@#$^()_+-=\{}|;':",./<>/L=CDE/ST=ABC/C=AU/CN=test~@#$^()_+ -=\{}|;':",./<>);
(undef, my %subjinfo) = split m|/?(\w+)=|, $subj;
print Dumper \%subjinfo;
输出
$VAR1 = {
'emailAddress' => 'test~@#$^()_+-=\{}|;\':",./<>',
'CN' => 'test~@#$^()_+ -=\{}|;\':",./<>',
'OU' => 'test~@#$^()_+-=\{}|;\':",./<>',
'L' => 'CDE',
'C' => 'AU',
'ST' => 'ABC',
'subject' => '',
'O' => 'test~@#$^()_+-=\{}|;\':",./<>'
};
我需要提取 $subj,如下面的代码片段所示,但看起来我的 Regex 没有按预期工作。这实际上与此类似:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my $subj =
'subject=/O=test~@#$^()_+-=\{}|;':",./<>/OU=test~@#$^()_+-=\{}|;':",./<>/emailAddress=test~@#$^()_+-=\{}|;':",./<>/L=CDE/ST=ABC/C=AU/CN=test~@#$^()_+ -=\{}|;':",./<>';
my %subjinfo = ( $subj =~ m,(\w+)=([^=]*)(?:/|$),g );
print Dumper \%subjinfo;
因此必须给出结果:
$VAR1 = {
'subject' => '',
'L' => 'NYC',
'C' => 'AMER',
'OU' => 'test~@#$^()_+-=\{}|;':",./<>',
'emailAddress' => 'test~@#$^()_+-=\{}|;':",./<>',
'ST' => 'AMER',
'CN' => 'test~@#$^()_+-=\{}|;':",./<>',
'O' => 'test~@#$^()_+-=\{}|;':",./<>'
};
这可能吗?你能建议一下吗?
拆分正则表达式看起来比仅使用正则表达式的解决方案更自然,
use Data::Dumper;
my $subj = q(subject=/O=test~@#$^()_+-=\{}|;':",./<>/OU=test~@#$^()_+-=\{}|;':",./<>/emailAddress=test~@#$^()_+-=\{}|;':",./<>/L=CDE/ST=ABC/C=AU/CN=test~@#$^()_+ -=\{}|;':",./<>);
(undef, my %subjinfo) = split m|/?(\w+)=|, $subj;
print Dumper \%subjinfo;
输出
$VAR1 = {
'emailAddress' => 'test~@#$^()_+-=\{}|;\':",./<>',
'CN' => 'test~@#$^()_+ -=\{}|;\':",./<>',
'OU' => 'test~@#$^()_+-=\{}|;\':",./<>',
'L' => 'CDE',
'C' => 'AU',
'ST' => 'ABC',
'subject' => '',
'O' => 'test~@#$^()_+-=\{}|;\':",./<>'
};