Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: perl regular expression

by reasonablekeith (Deacon)
on Oct 03, 2006 at 14:45 UTC ( [id://576087]=note: print w/replies, xml ) Need Help??


in reply to Re: perl regular expression
in thread perl regular expression

I know the OP had the word boundry match at the end, but I don't see its use here. Neither do I see the need for a non capturing group. Either way, the OP should probably positively match for the end of the file name, otherwise one might end up passing a file by virtue of a match part way through the filename.

The following wont print match...

my $filename = "/home/root/this_is_a_valid_name.html.gz"; if ($filename =~ m/(\.(htm|html|txt|pdf|ppt|csv|doc))$/i) { print "match\n"; # this won't print }
... however swap in the this one, and is passes just fine...
my $filename = "/home/root/this_is_a_valid_name.html.gz"; if ($filename =~ /(\.(?:htm|html|txt|pdf|ppt|csv|doc]))\b/i) { print "match\n"; # this will print }
---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re^3: perl regular expression
by chargrill (Parson) on Oct 03, 2006 at 18:15 UTC

    What happens when the filename is (arbitrarily contrived, but): magical.html_parser.dll?

    Though I suppose it matters what the OP wants to do with the file(s), and whether or not a .gz'd html/txt/etc file is desired.



    --chargrill
    s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2024-04-19 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found