[英]How to grep the word between two symbols in Perl?
I need to grep the word between the symbols as shown below in an array. 我需要在符号之间插入如下所示的数字。
my $string = "?hi how r u?what is your name?what is your age?";
It's to be converted to array where array should be like: 它将被转换为数组应该是这样的数组:
my $array[0]="hi how r u";
my $array[1]="what is your name";
my $array[2]="what is your age";
To ignore empty results you can match the input with regex and store matched results in an array: 要忽略空结果,可以将输入与正则表达式匹配,并将匹配结果存储在数组中:
use strict;
use warnings;
my $string = "?hi how r u?what is your name?what is your age?";
my @matches = ( $string =~ /(?<=\?)[^?]+/g );
foreach my $i (@matches) {
print $i . "\n";
}
Output: 输出:
hi how r u
what is your name
what is your age
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.