who needs negative find :-)

Tips on writing regular expressions for searching the post list

Moderators: Quade, dexter

who needs negative find :-)

Postby bobkoure » Fri Jun 08, 2007 5:03 pm

If you're looking to use find (rather than a filter) to not see something, you could use the "not followed by" operator
For instance, if I'm in an ebooks group and I want to not see pdbs I could use
^(?!.*pdb)
which means "start of line" "not followed by" "any chars" then "pdb"
or in a movies/mpeg group, I could use
^(?!.*wmv)
to hide windows media files.

Probably not a big deal, just something I've been using for a bit and I thought maybe someone else might find it useful.

Oh - and, yes, (?!pdb.*)$ works the same way - and, actually, I'd use something more like ^(?!.*\.pdb)

edit: typo fixed
Last edited by bobkoure on Mon Jun 11, 2007 3:26 pm, edited 1 time in total.
bobkoure
 

Postby nzzz » Sat Jun 09, 2007 7:21 pm

I have trouble trying to figure out new Regular Expressions.
I fill up the drop down list full of non-working expressions too fast.

Thanks for the tip.

I thought ^ was for Begins with, and ! was for NOT...
Last edited by nzzz on Sat Jun 09, 2007 8:00 pm, edited 1 time in total.
nzzz
Seasoned User
Seasoned User
 
Posts: 280
Joined: Thu Nov 10, 2005 9:50 pm

Registered Newsbin User since: 11/11/05

Postby richy99 » Sat Jun 09, 2007 7:53 pm

download regex buddy or look at regex sheets, i found it helped for me
User avatar
richy99
Elite NewsBin User
Elite NewsBin User
 
Posts: 6353
Joined: Fri Nov 21, 2003 8:04 pm
Location: Wales

Registered Newsbin User since: 12/31/03

Postby Smite » Sun Jun 10, 2007 8:39 pm

I never got into using lookaheads, so this is very welcome news. We've had this question a lot, and evidently have been giving the wrong answer. :)
Please read the FAQ before asking any questions.
If you're new to newsgroups, and the files on them, you can find a very helpful guide here.
User avatar
Smite
Katamari Damacy Addict
 
Posts: 5318
Joined: Sat May 19, 2001 1:54 am
Location: Alberta, Canada

Registered Newsbin User since: 03/27/03

Postby bobkoure » Fri Jun 15, 2007 11:14 pm

I forgot to mention - because look-aheads (and look-behinds) are "zero width assertions" you can just "stack 'em up"
so, to not see both pdbs and libs
^(?!.*pdb)(?!.*lib)
or neither pdbs, libs nor pdfs
^(?!.*pdb)(?!.*lib)(?!.*pdf)
etcetera - see how I don't have to mess with any additional logic?
bobkoure
 


Return to Regular Expressions

Who is online

Users browsing this forum: No registered users and 2 guests