inverse pattern matching!!!

Discussion in 'Perl Misc' started by chris, Oct 11, 2004.

  1. chris

    chris Guest

    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?
     
    chris, Oct 11, 2004
    #1
    1. Advertising

  2. chris

    Anno Siegel Guest

    chris <> wrote in comp.lang.perl.misc:
    > 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
     
    Anno Siegel, Oct 11, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DelphiDude
    Replies:
    3
    Views:
    1,169
  2. danpres2k
    Replies:
    3
    Views:
    7,476
    danpres2k
    Aug 25, 2003
  3. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    237
    Marc Bissonnette
    Jan 13, 2004
  4. Inverse Sequence Matching

    , Jun 9, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    92
    Tad McClellan
    Jun 9, 2006
  5. Bobby Chamness
    Replies:
    2
    Views:
    231
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page