I am trying to search and replace a string that is up to and including 3 characters in length with nothing (so ‘deleting’ the element contents).
So I have something like:
foreach (@array) {
s/^{1,3}$//;
}
E.g.
@array = ('one', 'two', 'three', 'four', 'five', 'six', 'seven');
So when printing, expected output would be:
result: result: result: three result: four result: five result: result: seven
So for the affected inputs, the output would be an ’empty place’.
This at the moment doesn’t happen… I’m betting I’m making a simple mistake due to my still-shaky understanding of regex. Any help appreciated!
If there is a simple way to actually remove the element totally without creating a new array, that would also be useful to know.
Simple regex problem aside, you can use
grepto select the elements you want:Then just print the results:
Results: