如何在大写字母和数字上拆分变量我的变量看起来像这样
$Var = "HvacSystem8000Series";
需要的结果是:
$Var = "Hvac System 8000 Series";
代码:
$Var =~ s/^[A-Z]/ /igs;
评论中的解释:
$Var = "HvacSystem8000Series";
$Var =~ s/(?<=[[:lower:]]) # Low case before,
(?=[[:upper:]0-9]) # upper case or digit after;
| # OR
(?<=[0-9]) # digit before,
(?=[[:upper:]]) # upper case after?
/\ /xg; # Replace with a space.
最简单的方法是收集您认为是单词的列表,然后用空格分隔符将它们重新连接在一起。
use strict;
use warnings;
my $var = "HvacSystem8000Series";
$var = join ' ', $var =~ /[A-Z]+[a-z]*|\d+/g;
print $var
输出
Hvac System 8000 Series