I’d like to split a string that has a certain repeating pattern, for example:
$string = "GGGGG-SOMETHING-ELSE-GGG-LAST";
to
@array=(-SOMETHING-ELSE-,-LAST);
my attempt so far as a perl newbie
split(/G{2,}/,$string);
Unfortunately this results in only patterns of GG being split on- not the greedy GGGGG or GGG patterns that I has hoped for resulting in 2 array elements.
No, this seems to (mostly) work as intended. The following code:
produces the output:
The issue is that there’s a first element that’s the empty string. So, to fix that, you can do something like:
And this produces what you want: