in reply to regex multi-line
or slurp the whole file and then grab the chunk you are interested in:my $last = ''; while (my $line = <$fh>) { if ( $last =~ m/USB\d*::0x[0-9a-fA-F::]+0x[0-9a-fA-F]+::[0-9a-f +A-F]+INSTR$/ and $line =~ m/USB\d*::0x[0-9a-fA-F::]+0x[0-9a-fA-F]+::[0-9a-f +A-F]+INSTR$/) { print "$last$line"; } $last = $line; }
my $content = do{local $/;<$fh>}; while ($content =~ /((?:USB\d*::0x[0-9a-fA-F::]+0x[0-9a-fA-F]+::[0-9a- +fA-F]+INSTR\n){2})/g) { print $1; }
I should mention that your posted regex is inconsistent with what I'm presuming your text looks like, so you should post your input file, wrapped in code tags so whitespace doesn't get mangled. You should also be aware that \s*(.+?)\s* will require at least 1 non-newline character in the text joining your two lines, since without the s modifer, . won't match a newline.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|