$s1 = '0000010000000100000100001';
$s1 =~ s/1(0+)1/'1'x((length($1)+2))/eg;
Output
0000011111111100000111111
| [reply] [d/l] |
It never occured to me that I could replace with a variable-length string. Oops. I feel pretty dumb now.
Thanks for your help!
| [reply] |
Use the s/// substitution operator:
$string =~ s/(?<=1)(0+)(?=1)/'1' x length($1)/eg;
Hope this helped.
CombatSquirrel.
Entropy is the tendency of everything going to hell. | [reply] [d/l] [select] |
Your description doesn't match your example. You say you
want to fill the area between the 1's with zero's, but
in your example, there are three area's between 1's, and
out of the three, you replace two of them with 1's.
If your question is, "how do I replace the 0's with 1's",
use tr:
tr/0/1/
Abigail | [reply] [d/l] |
s/(10*1)/1 x length($1)/eg;
Note that you might want to change the * to a + depending on what you want to happen should the ones be right next to each other. updatewording was "change the * to a star", thanks L~R-enlil | [reply] [d/l] |
As a sort of follow-up to Abigail-II's comment, note that for the string:
101110101
the three snippets posted so far give three different 'solutions' :-)
dave
| [reply] [d/l] |