Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Match something that does not match

by haukex (Chancellor)
on Feb 15, 2020 at 20:13 UTC ( #11113006=note: print w/replies, xml ) Need Help??


in reply to Match something that does not match

It seems to me like the feature you're implementing could be described as "stop matching at" (Update: or "match until") rather than do_not_match. Your current regex in do_not_match can be simplified to qr{ (?: (?!$pat) . )* }x; at least that still passes all your test cases. (This regex is pretty simple; I'm not sure if it warrants inclusion in Regexp::Common.)

Update: WebPerl Regex Tester

Replies are listed 'Best First'.
Re^2: Match something that does not match
by jo37 (Scribe) on Feb 15, 2020 at 20:42 UTC

    Your regex is indeed the one I was after. Though it works, I still don't get it :-(
    And I agree with you: this is too simple for Regexp::Common

    Thanks for your comment. Still learning...

    -jo

      Though it works, I still don't get it :-(

      The . matches anything (except newline), and (?!$pat) means "the next thing can't be $pat", so taken all together it really just means "match any number of characters, where none of these characters may be the first character of $pat".

        I was challenged by the mental step of putting something after a look-ahead assertion. Failing to understand this lead to the missing last character in the second branch of my original regex.
        Anyway, the fog lifts. Thanks a lot!

        -jo

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11113006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2020-04-09 03:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (47 votes). Check out past polls.

    Notices?