Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Negating Regexes: Tips, Tools, And Tricks Of The Trade

by diotalevi (Canon)
on Dec 07, 2006 at 16:24 UTC ( #588384=note: print w/ replies, xml ) Need Help??


in reply to Negating Regexes: Tips, Tools, And Tricks Of The Trade

I'd prefer to use this instead of Sidhekin's because it lets your pattern start it's match normally and doesn't require retrying at ever offset. The following lets the pattern match however it normally would but fails when it succeeds.

/(?(??{...})(?!))/;

In Perl 5.10, this is especially nice [Updated: Oops. Forgot the (?:...|) to have a success branch]

/...(*COMMIT)(?!)/;/(?:...(*COMMIT)(?!)|)/

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊


Comment on Re: Negating Regexes: Tips, Tools, And Tricks Of The Trade
Select or Download Code
Replies are listed 'Best First'.
Re^2: Negating Regexes: Tips, Tools, And Tricks Of The Trade
by demerphq (Chancellor) on Dec 07, 2006 at 17:33 UTC

    I'm not so sure that your example works as it stands. You'd need a code block to distinguish between true failure and false failure.

    In perl 5.10 you could do it like:

    if ( ! /...(*COMMIT:x)(*FAIL)/ && $REGERROR ne 'x' ) { ... }

    To be honest I need to think about how $REGERROR will work in the context of complete failure. For instance when failure occurs because of the optimiser. Hmm.

    ---
    $world=~s/war/peace/g

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2015-08-28 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (334 votes), past polls