Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Boolean operators in PERL regexp?

by ikegami (Pope)
on Feb 24, 2005 at 19:02 UTC ( #434196=note: print w/replies, xml ) Need Help??

in reply to Boolean operators in PERL regexp?

I recommend against using these (a parser would work better), but here's a snippet from my scratchpad:

/^(?:(?!$re).)*$/ # NOT re /$re1|$re2/ # re1 OR re2 /^(?=.*$re1)(?=.*$re2)/ # re1 AND re2

NOT must be anchored on both ends, but it doesn't have to be with ^ and $.

AND doesn't have to be anchored, but if the start is anchored (with ^ or by some other means), it should speed up the case where there is no match.

The .* in AND may need to be replaced so it doesn't look too far ahead.

Replies are listed 'Best First'.
Re^2: Boolean operators in PERL regexp?
by lenrobert (Initiate) on Feb 25, 2005 at 16:25 UTC
    Friedo, Enlinl, Ikegami, thank you for your responses.

    Yes, my problem might be easily solved with an HTML parser, but beyond my question in my opinion a logical NOT would be essential for regexps. Lookahead and lookbehind assertions are very good, the only fatal problem with them, that they are non-capturing, i.e. I cannot extract non-matching. Maybe there is a reason for this, I don't know.

      Whatcha talking about?
      NOT /XYZ/ vvvvvvvvvvvvv >perl -e "$_ = 'ABCDEFGHIJKL'; print(/ABC((?:(?!XYZ).)*)JKL/);" DEFGHI
        Ikegami, you're right. As it seems I needed some more help to use your code. Now it works, the final version is:
        /(<a href=("|))((?:(?!("|\/|#|javascript)).)*)(\s|"|>)/gi
        And $3 is the value of the href property.
        Thank you.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://434196]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2018-07-17 21:28 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (378 votes). Check out past polls.