in reply to rearranging matched parts of a string while using /g and without using split
One statement:
$_='A # B # 1 # 2'; print join ' # ', sub { map @_[$_,$_+@_/2], 0..$#_/2 }->( split / # / );
More readable:
sub pair { map @_[$_,$_+@_/2], 0..$#_/2 } $_='A # B # 1 # 2'; print join ' # ', pair split / # /;
I didn't see the purpose of avoiding split — you didn't say what you didn't like about it — but you could replace
split / # /
with
/(?:(?! # ).)*/sg
|
---|