Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.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,我想结合两个正则表达式模式来拆分字符串并得到一个整数表 这是一个例子: $string= "1..1188,1189..14,14..15"; $first_pattern = /\../; $second_pattern = /\,/; 我想得到这样的标签: [1,1188,1189,14,14,15] 使用|连接备选方案。另外,使用qr/创建正则表达式对象,使用普通的/…/匹配$并将结果分配给$第一个\u模式和$第二个\u模式 #!/usr/bin/perl use warnings;

我想结合两个正则表达式模式来拆分字符串并得到一个整数表

这是一个例子:

$string= "1..1188,1189..14,14..15";
$first_pattern = /\../;
$second_pattern = /\,/;
我想得到这样的标签:

[1,1188,1189,14,14,15]

使用
|
连接备选方案。另外,使用
qr/
创建正则表达式对象,使用普通的
/…/
匹配
$并将结果分配给
$第一个\u模式
$第二个\u模式

#!/usr/bin/perl
use warnings;
use strict;
use feature qw{ say };

my $string = '1..1188,1189..14,14..15';
my $first_pattern = qr/\.\./;
my $second_pattern = qr/,/;

my @integers = split /$first_pattern|$second_pattern/, $string;
say for @integers;
您可能需要
\.\.
来匹配两个点,因为
\..
匹配的是一个点后跟除换行符以外的任何字符。此外,不需要反斜杠逗号