Perl 按大写字母和数字拆分
我需要这个脚本来拆分大写字母和数字。我已经把大写字母部分分开了,但我似乎不知道它的数字部分 所需结果:Perl 按大写字母和数字拆分,perl,cgi,cgi-bin,Perl,Cgi,Cgi Bin,我需要这个脚本来拆分大写字母和数字。我已经把大写字母部分分开了,但我似乎不知道它的数字部分 所需结果:Hvac系统8000系列::供暖系统8000系列::锅炉 #!/usr/bin/perl print "Content-type: text/html\n\n"; use CGI qw(:standard); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use strict; my $Last_URL = "HvacSystem
Hvac系统8000系列::供暖系统8000系列::锅炉
#!/usr/bin/perl
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
my $Last_URL = "HvacSystem8000Series/HeatingSystem8000Series/Boilers";
my ($Cat,$Sub1,$Sub2) = split(/\//, $Last_URL, 3);
if ($Sub2) {
$Last_URL = "<b>$Cat :: $Sub1 :: $Sub2</b>";
}
else {
$Last_URL = "<b>$Cat :: $Sub1</b>";
}
my @Last_URL = $Last_URL =~ s/(.)([A-Z][^A-Z][^0-9])/$1 $2/g;
print "$Last_URL";
#/usr/bin/perl
打印“内容类型:text/html\n\n”;
使用CGI qw(:标准);
使用CGI::Carp qw(警告浏览者fatalsToBrowser);
严格使用;
my$Last\u URL=“HvacSystem8000Series/HeatingSystem8000Series/Boilers”;
my($Cat,$Sub1,$Sub2)=拆分(/\/,$Last\u URL,3);
如有的话(2美元以下){
$Last_URL=“$Cat::$Sub1::$Sub2”;
}
否则{
$Last_URL=“$Cat::$Sub1”;
}
我的@Last_URL=$Last_URL=~s/()([A-Z][^A-Z][^0-9])/$1$2/g;
打印“$Last_URL”;
一些s//
转换将为您提供所需的:
for ($Last_URL) {
s/ ([a-z]) ([A-Z0-9]) / "$1 $2" /egx; # Foo123 -> Foo 123
s/ ([0-9]) ([A-Z]) / "$1 $2" /egx; # 123Bar -> 123 Bar
s! / ! " :: " !egx; # / -> " :: "
}
print $Last_URL, "\n";
我建议您使用正则表达式匹配来查找字符串中所有必需的“单词”,然后用空格连接它们。这个程序演示了。它将
/
计算为一个单词,因此可以用它们代替双冒号来完成这个过程
use strict;
use warnings;
my $Last_URL = "HvacSystem8000Series/HeatingSystem8000Series/Boilers";
(my $string = join ' ', $Last_URL =~ m<[A-Z][a-z]*|\d+|/>g) =~ s|/|::|g;
print $string;
就像皮尔克罗的回答,但是,你知道,不同
#!/usr/bin/env perl
use strict;
use warnings;
my $string = "HvacSystem8000Series/HeatingSystem8000Series/Boilers";
$string =~ s/(?<=\p{Ll})(?=\p{Lu}|\pN)/ /g;
$string =~ s/(?<=\pN)(?=\p{Lu})/ /g;
$string =~ s'/' :: 'g;
print "$string\n";
#/usr/bin/env perl
严格使用;
使用警告;
my$string=“HVACSystem8000系列/加热系统8000系列/锅炉”;
$string=~s/(?)?
#!/usr/bin/env perl
use strict;
use warnings;
my $string = "HvacSystem8000Series/HeatingSystem8000Series/Boilers";
$string =~ s/(?<=\p{Ll})(?=\p{Lu}|\pN)/ /g;
$string =~ s/(?<=\pN)(?=\p{Lu})/ /g;
$string =~ s'/' :: 'g;
print "$string\n";