使用perl表达式查找字符串中的最小模式
我试图在(2个字符)字符串中找到最小模式示例:使用perl表达式查找字符串中的最小模式,perl,Perl,我试图在(2个字符)字符串中找到最小模式示例: 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
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
它总是有两个字符“a”和“b”,而且总是有一个模式,
仅限“a”或“b”的角落案例。
非常感谢您的帮助
谢谢你,迈克尔
my ($repeated_pattern) = $str1 =~ /^(.+?)\1+\z/s;