in reply to how to replace a matched pattern in a string with a different pattern of same length?
I know to search for longest string separated by 1's, I would use =~ /(1.*1)/, but here "." will pick 0's and 1's both, and I only want 1's. I tried few other combinations but didn't seem to work. any suggestions?
And 1{1,}1 is just nonsense. It matches a minimum of two 1's, but certainly does not match the longest run of 1's in a string--it just matches the *first* run of 1's that has at least two 1's in it. For instance,
use strict; use warnings; use 5.010; my $str = '110011111111'; $str =~ s/1{1,}1/*/; say $str; --output:-- *0011111111
|
|---|