inverse pattern matching!!!

C

chris

Background: I have a little program that scans pathnames and does
something worthile if a match is generated. Equally, I have a config
file with lines representing patterns to skip. To skip lines I have
the following (sort of):
if ($pathname =~ m,^$pattern$,) {;#skip it} else {;#do something
worthwhile}

Initially I want to skip home directories: '/home/.*' worked a treat.
Now I need to skip all, but not anything with '.ssh' in it.
so '/home/fred/.ssh' or '/home/tom/.ssh/known_hosts' is not excluded.

Now I know this must be simple but can I figure out a clean inverse of
'/home/.*?/.ssh'.

Any ideas gurus?
 
A

Anno Siegel

chris said:
Background: I have a little program that scans pathnames and does
something worthile if a match is generated. Equally, I have a config
file with lines representing patterns to skip. To skip lines I have
the following (sort of):
if ($pathname =~ m,^$pattern$,) {;#skip it} else {;#do something
worthwhile}

Initially I want to skip home directories: '/home/.*' worked a treat.
Now I need to skip all, but not anything with '.ssh' in it.
so '/home/fred/.ssh' or '/home/tom/.ssh/known_hosts' is not excluded.

Now I know this must be simple but can I figure out a clean inverse of
'/home/.*?/.ssh'.

Any ideas gurus?

Use negative lookahead.

It would be more efficient to reverse (or extend) the logic in
configuration processing (that is, make positive selection possible).

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top