Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: regexp to check if file name matches pattern

by smanicka (Scribe)
on Feb 24, 2009 at 22:24 UTC ( [id://746127]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://746127]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2025-04-25 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.