Regex feature request

Tips on writing regular expressions for searching the post list

Moderators: Quade, dexter

Regex feature request

Postby optiman » Fri Oct 23, 2009 11:10 am

Quade can you add in the regex feature to "exclude" results? I think it's the ^operator, so you return all search results that DON'T include the ^[text] string. That would eliminate junk posts that litter results containing that string. I don't want to create a filter for it as it is usually a one-off situation.
Thanks
User avatar
optiman
Seasoned User
Seasoned User
 
Posts: 251
Joined: Tue Aug 05, 2003 1:06 am

Registered Newsbin User since: 12/13/03

Postby itimpi » Fri Oct 23, 2009 11:36 am

As far as I know there is no regex operator to exclude (the ^ operator means anchor to start) which I have always though was a shame. I am sure Quade is just using a standard RegEx engine - not something custom written for Newsbin.
The Newsbin Online documentation
The Usenettools for tutorials, useful information and links
User avatar
itimpi
Elite NewsBin User
Elite NewsBin User
 
Posts: 12607
Joined: Sat Mar 16, 2002 7:11 am
Location: UK

Registered Newsbin User since: 03/28/03

Postby ozzii » Sat Oct 24, 2009 8:50 am

There is NO exclude for regex :cry:
ozzii
Seasoned User
Seasoned User
 
Posts: 410
Joined: Thu Feb 23, 2006 6:10 pm
Location: France

Registered Newsbin User since: 02/23/06

Postby optiman » Sat Oct 24, 2009 12:22 pm

You're right, I must have misunderstood regex examples on the web. Too bad, I'd still love to see an "exclude string" capability to eliminate garbage postings.
User avatar
optiman
Seasoned User
Seasoned User
 
Posts: 251
Joined: Tue Aug 05, 2003 1:06 am

Registered Newsbin User since: 12/13/03

Postby ozzii » Sun Oct 25, 2009 6:26 am

Add you word to exclude into the exclude filter !
ozzii
Seasoned User
Seasoned User
 
Posts: 410
Joined: Thu Feb 23, 2006 6:10 pm
Location: France

Registered Newsbin User since: 02/23/06

Postby optiman » Wed Oct 28, 2009 5:26 pm

As I said in my first post, I don't want a permanent filter for occasional garbage posts.
User avatar
optiman
Seasoned User
Seasoned User
 
Posts: 251
Joined: Tue Aug 05, 2003 1:06 am

Registered Newsbin User since: 12/13/03

Postby bobkoure » Tue Nov 24, 2009 12:55 pm

Why not use lookahead?
negative lookahead:
(?!foo) means not followed by "foo".
^(?!.*foo) means start of line not followed by any number of chars and then "foo"
positive lookahead:
(?=bar) means followed by "bar"
^(?=.*bar) means start of line followed by any number of chars and then "bar" .

Lookahead is a regex "zero width operator", which means (among other things) that you can stack 'em, so...

^(?!.*foo)(?=.*bar)
Will pick up any lines that have "bar" but not "foo".
bobkoure
 

Postby viking » Wed Nov 25, 2009 4:05 pm

bobkoure wrote:Why not use lookahead?
negative lookahead:
(?!foo) means not followed by "foo".
^(?!.*foo) means start of line not followed by any number of chars and then "foo"
positive lookahead:
(?=bar) means followed by "bar"
^(?=.*bar) means start of line followed by any number of chars and then "bar" .

Lookahead is a regex "zero width operator", which means (among other things) that you can stack 'em, so...

^(?!.*foo)(?=.*bar)
Will pick up any lines that have "bar" but not "foo".

I was looking for the same thing, with a twist:

I would like to exclude all posts with "foo" except those with "newfoo"?
(The simple negative lookahead above, (?!foo), also excludes "newfoo")
User avatar
viking
Seasoned User
Seasoned User
 
Posts: 601
Joined: Sat Jul 26, 2003 5:53 am
Location: California

Postby bobkoure » Fri Nov 27, 2009 12:18 pm

You could try '\b', which is another "zero width" operator - means "word boundary"
\bfoo\b matches foo 1foo 1234foo33 but not newfoo

So... ^(?!.*\bfoo\b) is all posts not including the word foo.
bobkoure
 

Postby viking » Sat Nov 28, 2009 8:54 pm

bobkoure wrote:You could try '\b', which is another "zero width" operator - means "word boundary"
\bfoo\b matches foo 1foo 1234foo33 but not newfoo

So... ^(?!.*\bfoo\b) is all posts not including the word foo.

Great. Thanks!!
User avatar
viking
Seasoned User
Seasoned User
 
Posts: 601
Joined: Sat Jul 26, 2003 5:53 am
Location: California


Return to Regular Expressions

Who is online

Users browsing this forum: No registered users and 1 guest