in reply to Re^2: How do I display only matches
in thread (SOLVED) How do I display only matches

use strict; use warnings; my $filename = 'dirtest.txt'; open(my $fh, '<:encoding(UTF-8)', $filename) or die "Could not open file '$filename' $!"; while (my $row = <$fh>) { chomp $row; next if $row =~ /.{20}\\[a-zA-Z]\s[\r\n]/; print "$row\n"; }

The following is the file content:

Directory of D:\ \Q\X 09/20/2019 07:57 PM <DIR> . 09/20/2019 07:57 PM <DIR> ..

The regex works for this content in online regex https://regex101.com/r/LFrvLp/11 But when I run the script, EVERY row is displayed, it should only be the FIRST row as it is the only row with a backslash in position 21.

Replies are listed 'Best First'.
Re^4: How do I display only matches
by AnomalousMonk (Archbishop) on Sep 24, 2019 at 05:08 UTC

    Please see this.


    Give a man a fish:  <%-{-{-{-<