in reply to Re^2: Find a pattern
in thread Find a pattern

It's a slightly tricky match to get right depending on just how fussy you really want to be. Using a negative look ahead helps cover most bases though. Consider:

use strict; use warnings; my $str = <<STR; Errors: 0 failed Errors: 01 failed Errors: 1 failed Errors: 10 failed Errors: None failed Ben10 failed STR open my $fIn, '<', \$str; while (<$fIn>) { print if /\b(?!0+\b)\d{1,9} failed/; }

Prints:

Errors: 01 failed Errors: 1 failed Errors: 10 failed

The (?!0+\b) is the negative look ahead that fails the match if a zero value (regardless of the number of 0 digits) is found. The \b's are there to ensure all the digits in the number are matched.

True laziness is hard work