Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在perl中从字符串中提取数字_Perl - Fatal编程技术网

在perl中从字符串中提取数字

在perl中从字符串中提取数字,perl,Perl,我有这两条线。如何从它们中提取7个字符的十进制数 来自字符串1的值为13682.0,来自字符串2的值为13681.9 十进制数始终为7个字符,并且始终以xxxxx.x的形式出现。请尝试使用正则表达式和匹配运算符执行此操作: $string1 = "2_0_1AU13682.0AV+0.2" $string2 = "2_0_1AT+0.1CD13681.9" 请参阅和。尝试使用正则表达式和匹配运算符执行此操作: $string1 = "2_0_1AU13682.0AV+0.2" $strin

我有这两条线。如何从它们中提取7个字符的十进制数

来自字符串1的值为13682.0,来自字符串2的值为13681.9

十进制数始终为7个字符,并且始终以xxxxx.x的形式出现。请尝试使用正则表达式和匹配运算符执行此操作:

$string1 = "2_0_1AU13682.0AV+0.2"

$string2 = "2_0_1AT+0.1CD13681.9"
请参阅和。

尝试使用正则表达式和匹配运算符执行此操作:

$string1 = "2_0_1AU13682.0AV+0.2"

$string2 = "2_0_1AT+0.1CD13681.9"

请参见和。

使用正则表达式,如下所示:

my $string1 = "2_0_1AU13682.0AV+0.2";
my ($res) = $string1 =~ m/(\d{5}\.\d)/; 
print $res, "\n";
产出:

my @data = qw( 2_0_1AU13682.0AV+0.2 2_0_1AT+0.1CD13681.9 );

foreach my $str (@data) {

    if ($str =~ /(\d{5}\.\d)/) {
        print $1, "\n";
    }

}

使用正则表达式,如下所示:

my $string1 = "2_0_1AU13682.0AV+0.2";
my ($res) = $string1 =~ m/(\d{5}\.\d)/; 
print $res, "\n";
产出:

my @data = qw( 2_0_1AU13682.0AV+0.2 2_0_1AT+0.1CD13681.9 );

foreach my $str (@data) {

    if ($str =~ /(\d{5}\.\d)/) {
        print $1, "\n";
    }

}