[英]Perl regular expression pattern length
我想在一個字符串中搜索一個特定的模式,但具有特定的長度(最大長度為20)。 例:
串:
hellokkkkkkkkkkhellokhellokkhellokkkkk
正則表達式:
/(hello.*?hello.*?hello)/
但它給了我以下的模式
loc:0到26
hellokkkkkkkkkkhellokhello
但我想要的只是長度<20的第二種模式(意味着hellokhellokkhello
)。有什么建議嗎?
要獲得重疊匹配,請使用前瞻 。
my $string = 'hellokkkkkkkkkkhellokhellokkhellokkkkk';
say for
grep { length($_) < 20 }
$string =~ /(?=(hello.*?hello.*?hello))/g;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.