in reply to Re: how to check whether a particular word exists in filename
in thread how to check whether a particular word exists in filename

"...but not 'CHECK_ABC123_A1.txt' "

Nope! Not true.

C:\>perl -E "my $s='CHECK_ABC123_A1.txt';say $s if ($s =~ m/^CHECK_(\w ++)\.txt/ );" CHECK_ABC123_A1.txt

or, alternately,

#!/usr/bin/perl use 5.016; use strict; use warnings; # 1042260 my $s='CHECK_ABC123_A1.txt'; if ( $s =~ m/^CHECK_(\w+)\.txt/ ) { say "\t \$1 is: $1\n\t and the regex matched the source string."; } else { say "\t Nope. Regex didn't match \$s."; } =head OUTPUT: $1 is: ABC123_A1 and the regex matched the source string. =cut

Pls test your advice... (unless you were trying to get a clueless OP to turn in homework with an error).


If you didn't program your executable by toggling in binary, it wasn't really programming!

Replies are listed 'Best First'.
Re^3: how to check whether a particular word exists in filename
by Happy-the-monk (Canon) on Jul 03, 2013 at 23:30 UTC

    Nope! Not true.

    That is because in the character class [A-Za-z0-9] there is no underscore, and Preceptor assumed that would be equivalent to \w .
    \w , however, is [A-Za-z0-9_] and thus includes the underscore.

    Cheers, Sören

    (hooked on the Perl Programming language)