in reply to split but preserve the matching pattern
I'm not sure I understand exactly what you are looking for, but here's my best guess. This splits the text you provided on the word "command", retains the pattern in the results, and spans newlines. If you're looking for something else (e.g., splitting only lines containing "command"), please be more specific and we can go from there.
The @results array contains two elements:use strict; use warnings; use Data::Dumper; my $string = "command = adb asd 2t525 command=adfaf adsgadg asd"; my @results = split( /(?=command)/, $string ); print Dumper( \@results );
HTH$VAR1 = [ 'command = adb asd 2t525 ', 'command=adfaf adsgadg asd' ];
|
|---|