Find the minimum pattern in a string using the perl expression

I am trying to find the minimum pattern in string examples (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 

it is always 2 characters 'a' and 'b', and there is always a pattern, there are no angular cases of “a” or “b”. any help is appreciated.

thanks michael

+4
source share
1 answer
 my ($repeated_pattern) = $str1 =~ /^(.+?)\1+\z/s; 
+6
source

Source: https://habr.com/ru/post/1481444/


All Articles