perl reg expression help.

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am looking to compile a regular expression to meet the following req's if
anybody hands on with perl can help

1. looking for string 'files' (in a given folder location) i.e. C:\program
files\files or /home/files
2. string should match any case (upper/lower and mix)
3. string should occur at the end (whats leading is regardless)
4. if there are multiple occurences (i.e. program files\files) it should match
the last one only

Many Thanks

Re: perl reg expression help.

On Mar 8, 6:16=A0am, Master Chief Petty Officer John-117
Quoted text here. Click to load it

Probably easiest to use grep. This command returns all instances of
"files" contained in any file in the current working directory:

grep files *

That should be enough to get you started. Look for 'case insensitive'
and 'word boundary' switches.


Re: perl reg expression help.

Quoted text here. Click to load it

If you happen to be using an operating system that provides useful
tools, then you do not need regular expressions, nor even perl,
to meet all of your requirements:

    find . -iname '*files'

Quoted text here. Click to load it

[ you meant e.g. (for example) rather than i.e. (that is)]

You are not looking for a string. You are looking (recursively)
for a filename.

Looks like you might not have the useful tool above...

Quoted text here. Click to load it

... so write one in Perl then.

use warnings;
use strict;
use File::Find;

die "provide an argument\n" unless @ARGV;

find sub {print "$File::Find::name\n" if  /$ARGV[0]$/i}, '.';

Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg0cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.

Site Timeline