Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Match AND NOT-match in one perl RegExp.

Expand Messages
  • Jeff 'japhy' Pinyan
    ... Ok: $rx1 = qr/[ x2D_%a-z x91 x9B x86A-Z x92 x9D x8F0-9]+$/; $rx2 = qr/unknown$/; if ($str =~ /^(?=$rx1)(?!$rx2)/) { # matches rx1 and not rx2 } That s how
    Message 1 of 5 , May 1 9:08 AM
    • 0 Attachment
      On May 1, Allan Dystrup said:

      >1) ^[\x2D_%a-z\x91\x9B\x86A-Z\x92\x9D\x8F0-9]+$
      >2) ^unknown$
      >
      >I want (for good reasons) to combine these into *one* regexp $Filter
      >stating :
      >1) MATCH on the character class, AND (if so)
      >2) MATCH on NOT "unknown"

      Ok:

      $rx1 = qr/[\x2D_%a-z\x91\x9B\x86A-Z\x92\x9D\x8F0-9]+$/;
      $rx2 = qr/unknown$/;

      if ($str =~ /^(?=$rx1)(?!$rx2)/) {
      # matches rx1 and not rx2
      }

      That's how to do it.

      --
      Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
      RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
      CPAN ID: PINYAN [Need a programmer? If you like my work, let me know.]
      <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    • Allan Dystrup
      Hi Jeff, This was just the solution i was lookung for, thanks a bucket! The problem with reversing a logically straight forward regexp (as you have to, not
      Message 2 of 5 , May 2 5:29 AM
      • 0 Attachment
        Hi Jeff,

        This was just the solution i was lookung for, thanks a bucket!

        The problem with reversing a logically straight forward regexp (as
        you have to, not using the extended constructs) is that it - even
        after years of yoga training - seems to stare back at you like a line
        straight out of of Gödels theorem. You wouldn't like to run into that
        in a dark alley in someone else's code...

        allan


        --- In perl-beginner@yahoogroups.com, Jeff 'japhy' Pinyan
        <japhy@p...> wrote:
        > On May 1, Allan Dystrup said:
        >
        > >1) ^[\x2D_%a-z\x91\x9B\x86A-Z\x92\x9D\x8F0-9]+$
        > >2) ^unknown$
        > >
        > >I want (for good reasons) to combine these into *one* regexp
        $Filter
        > >stating :
        > >1) MATCH on the character class, AND (if so)
        > >2) MATCH on NOT "unknown"
        >
        > Ok:
        >
        > $rx1 = qr/[\x2D_%a-z\x91\x9B\x86A-Z\x92\x9D\x8F0-9]+$/;
        > $rx2 = qr/unknown$/;
        >
        > if ($str =~ /^(?=$rx1)(?!$rx2)/) {
        > # matches rx1 and not rx2
        > }
        >
        > That's how to do it.
        >
        > --
        > Jeff "japhy" Pinyan japhy@p...
        http://www.pobox.com/~japhy/
        > RPI Acacia brother #734 http://www.perlmonks.org/
        http://www.cpan.org/
        > CPAN ID: PINYAN [Need a programmer? If you like my work, let me
        know.]
        > <stu> what does y/// stand for? <tenderpuss> why, yansliterate of
        course.
      Your message has been successfully submitted and would be delivered to recipients shortly.