Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How do I write a regex for 'does not contain' a string.

by Abigail-II (Bishop)
on Aug 09, 2002 at 13:58 UTC ( [id://188912]=note: print w/replies, xml ) Need Help??


in reply to How do I write a regex for 'does not contain' a string.

/^(?:[^f]+|f(?!oo))*$/; # Matches strings not containing 'foo'. /^(?:(?!PATTERN).)*$/; # Matches strings not containing PATTERN +.
The top one is reasonably fast, the bottom one is slow, but works for all patterns.

Abigail

Replies are listed 'Best First'.
Re: Re: How do I write a regex for 'does not contain' a string.
by IraTarball (Monk) on Aug 09, 2002 at 17:03 UTC
    Excelent! Thank you. I knew there must be a way to do this. Dispite the very valid points by fruiture and arturo about a better way to solve my particular problem, it was bugging me that I couldn't think of a way to do this.

    With much thanks,
    Ira

    "So... What do all these little arrows mean?"
    ~unknown

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2025-01-17 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (55 votes). Check out past polls.