Matthew L. Abrasax Matthew L. Abrasax - 7 months ago 32
Perl Question

perl: print remaining string only if there is no character before the matched value.

The following prints the entire content of the line after "B. "

perl -ne'print if /B[.] (.*)/s' $string > file

How can I match/print the line only if there is no other character before the "B. "? In other words, if there is a character before the
"B. "
skip the line / do not print.

The correct "B." is always on a new line, the only correct line to match appears as follows:

B. some text here


A regex with a leading carat indicates that the expression should match only if it is the first item on the line. The pattern /^B[.] (.*)/s should get you the result you're looking for.