【发布时间】:2019-10-30 20:15:09
【问题描述】:
我想搜索一个与另一个字符串中的确切时间匹配的字符串,但遇到了一些问题。
use strict;
use warnings;
my $test="abc1234abc5678abcdef910";
my $cut_seq="abc";
print $test,"\tone time\n" if($test=~/$cut_seq{1}/);
print $test,"\tmore than one times\n" if($test=~/$cut_seq{1,}/);
我期待结果:
abc1234abc5678abcdef910 more than one times
但结果显示为:
abc1234abc5678abcdef910 one time
abc1234abc5678abcdef910 more than one times
我也试过这个:
print $test,"\tone time\n" if($test=~/$cut_seq{0,1}/);
print $test,"\tone time\n" if($test=~/$cut_seq{1,1}/);
print $test,"\tmore than one times\n" if($test=~/$cut_seq{1,}/);
但没有任何改变。我只是想知道为什么它不能匹配确切的时间。如果某事物匹配两次,它也会匹配一次,那么 {1}、{1,}、{1,1}、{1,2} 有什么区别。我不明白创建这些不同的形式。
【问题讨论】:
-
仅供参考:
{1,}的意思不是“超过一次”而是“一次或多次” -
@TOto,我很抱歉这个错误。