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. Advertisements

  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. Advertisements

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,360
  2. danpres2k
    Replies:
    3
    Views:
    7,661
    danpres2k
    Aug 25, 2003
  3. CV
    Replies:
    2
    Views:
    723
    Charles DeRykus
    Aug 31, 2004
  4. seema

    perl pattern matching

    seema, Mar 12, 2005, in forum: Perl
    Replies:
    1
    Views:
    827
    Bob Walton
    Mar 12, 2005
  5. Calum MacLean
    Replies:
    4
    Views:
    1,335
    Calum MacLean
    Jul 8, 2004
  6. Marc Bissonnette

    Pattern matching : not matching problem

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

    , Jun 9, 2006, in forum: Perl Misc
    Replies:
    2
    Views:
    142
    Tad McClellan
    Jun 9, 2006
  8. Bobby Chamness
    Replies:
    2
    Views:
    491
    Xicheng Jia
    May 3, 2007
Loading...