in reply to Number of digits at the end of the string

I'm confused. When I run the code that you posted, it prints (contrary to your claim):
No Match... :(

Perhaps you updated your original post?

Replies are listed 'Best First'.
Re^2: Number of digits at the end of the string
by rowdog (Curate) on Jan 17, 2008 at 21:03 UTC
    grinder's solution works for me (grinder++). Here's my test against your strings..
    #!/usr/bin/perl use strict; use warnings; my @strings = qw/aaa_gjh1_dfgdf_0009 aaa_gjh_0000 00000 aaa_fdsfs_000 +aaa_sdf_jdsh_01111/; print is_valid($_) ? '' : "no ", "match: $_\n" for @strings; sub is_valid { my $test = shift; return $test =~ /\Aaaa_\w{1,24}(?<=\D)\d{4}\z/; }
      Thanks for the solution but this still says Match for aaa_fgjkghd11_hfksdh11__0000 ( two underscores)

        Well -- to you, talk about ungrateful. It would be better to state more clearly what you want up front.

        Adding this additional constraint changes the pattern but a little. Were you to study perlre, you could probably have done it yourself.

        sub is_valid { my $test = shift; return $test =~ /^aaa_\w{1,24}(?<!_)_\d{4}$/; }

        • another intruder with the mooring in the heart of the Perl