4

我试图在(2 char)字符串示例中找到最小模式:

enter code here

 #!/usr/bin/perl
 use warnings;
 use strict;


 my $str1;
 $str1 = 'abbabbabbabbabb'; #  abb is repeating  
 $str1 = 'abababababababa';  #  ab is repeating 
 $str1 = 'abaaaabaaaabaaa';  #  abaaa is repeating
 $str1 = 'bbaabbaabbaabbaa'; #  bbaa is repeating 

它总是2个字符'a'和'b',并且总是有一个模式,没有'a'或'b'的极端情况。任何帮助是极大的赞赏。

谢谢迈克尔

4

1 回答 1

6
my ($repeated_pattern) = $str1 =~ /^(.+?)\1+\z/s;
于 2013-05-17T18:12:06.147 回答