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

Re: [PBML] Re: Compact digital range RexEx - And complement?

Expand Messages
  • J.E. Cripps
    ... everything I ve seen indicates that there isn t any such feature, and the complementing a regexp tends to be laborious, messy or both ... the ^ should be
    Message 1 of 20 , Dec 1, 2004
      On Wed, 1 Dec 2004, Allan Dystrup wrote:

      > Yes i can follow your line of reasoning here, step by step building up
      > the "negated" Regex'es. ...
      > It is workable (actually more 'work' than 'able' to my taste...), so
      > what i was really looking for was a built-in Regex
      > operator/metacharacter like [^ ] for char. classes or (?! ) for
      > lookahead, a feature that would just "invert" any given Regex, so to
      > speak.

      everything I've seen indicates that there isn't any such feature,
      and the complementing a regexp tends to be laborious, messy or both


      another error in a previous message of mine:

      > > (C^[X])(\d{3})| # match the initial C

      the ^ should be _inside_ the [ ], i.e.

      (C[^X])(\d{3})

      > > (J^[ABYZ]))(\d{1})| # match J followed by

      which should be

      (J[^ABYZ])(\d{1})
    • Jonathan Paton
      Dear Allan, I think you are looking for: (?!pattern) A zero-width negative look-ahead assertion. For example /foo(?!bar)/ matches any occurrence of foo
      Message 2 of 20 , Dec 1, 2004
        Dear Allan,

        I think you are looking for:

        "(?!pattern)"
        A zero-width negative look-ahead assertion. For example
        "/foo(?!bar)/" matches any occurrence of "foo" that isn't
        followed by "bar". Note however that look-ahead and look-
        behind are NOT the same thing. You cannot use this for
        look-behind.

        ...

        from perldoc perlre

        You might need to wrap the regex with ^ and $ assertions.

        Jonathan Paton
      • Allan Dystrup
        Hi Jonathan , Yes indeed, i ve reached the same conclusion. The (?!pattern) can solve the issue in as clean a way as it s probably possible with Regex es. Eg:
        Message 3 of 20 , Dec 1, 2004
          Hi Jonathan ,

          Yes indeed, i've reached the same conclusion.
          The (?!pattern) can solve the issue in as clean a way
          as it's probably possible with Regex'es. Eg:

          Range RegEx Complement
          ----------- ----------- ----------
          CX365-CX366 CX36(5|6) ^(?!CX36(5|6))
          JA300-JA302 JA30[0-2] ^(?!JA30[0-2])
          JA320-JA394 JA3(([2-8]\d)|(9[0-4])) ^(?!(JA3(([2-8]\d)|(9[0-4]))
          etc.

          Thanks a lot,
          Allan


          --- In perl-beginner@yahoogroups.com, Jonathan Paton <jepaton@g...>
          wrote:
          > Dear Allan,
          >
          > I think you are looking for:
          >
          > "(?!pattern)"
          > A zero-width negative look-ahead assertion. For
          example
          > "/foo(?!bar)/" matches any occurrence of "foo"
          that isn't
          > followed by "bar". Note however that look-ahead
          and look-
          > behind are NOT the same thing. You cannot use
          this for
          > look-behind.
          >
          > ...
          >
          > from perldoc perlre
          >
          > You might need to wrap the regex with ^ and $ assertions.
          >
          > Jonathan Paton
        Your message has been successfully submitted and would be delivered to recipients shortly.