in reply to regexp to check if file name matches pattern

Hello Dave, it doesn't work.I tried:
#!/usr/bin/perl $file= "SYSB_A31.GROUPINS%RDEBLIST%REAPPLY%2008.12.16.20.31.35.pdf"; if ($file=~ /^SYS(?:[^%]+%)+[^.]*\.pdf/i){ print "yes"; } else{ print "no"; }
and it prints out no. Thanks Smanicka

Replies are listed 'Best First'.
Re^2: regexp to check if file name matches pattern
by davido (Cardinal) on Feb 24, 2009 at 22:34 UTC

    Lol, I had no way of knowing that your date field was "dot delimited." My solution would naturally reject that. Here's a new approach that should do the trick given that new, previously unmentioned requirement.

    /^SYS(?:[^%]+%){2,}[\d.]+\.pdf/i

    Let me know how that works out. This time I'm specifically allowing the 'dot' delimiter in the date field. This solution is going to result in some backtracking though. It might be better written as:

    /^SYS(?:[^%]+%){2,}(?:\d+)(?:.\d+)+\.pdf/i

    This will get less backtracking, and thus should be a little more efficient, if that matters.


    Dave

Re^2: regexp to check if file name matches pattern
by smanicka (Scribe) on Feb 24, 2009 at 22:28 UTC
    tried {2,} instead of + as suggested.since prints out no