AND

Tips on writing regular expressions for searching the post list

Moderators: Quade, dexter

AND

Postby obvious » Tue Aug 20, 2002 2:44 pm

I'm wondering if I can build a case insensitive substring search using 'AND' or its equivalent?

e.g. I want to match ("geriatric" OR "GeriaTRic) AND ("Llama" OR 'llAMa') AND ("PROn" OR "prOn") anywhere in the subject line
User avatar
obvious
Seasoned User
Seasoned User
 
Posts: 584
Joined: Wed Jun 06, 2001 8:30 pm

Registered Newsbin User since: 04/13/03

RE: AND

Postby obvious » Wed Aug 21, 2002 1:02 pm

LAST EDITED ON 08-21-02 AT 12:05 PM (EST)
I thought the above might be impossible with regex. Are there any plans for alternative filtering for 5.0?

Also, what does everyone think? Should NB just stick to regex parsing or not?
User avatar
obvious
Seasoned User
Seasoned User
 
Posts: 584
Joined: Wed Jun 06, 2001 8:30 pm

Registered Newsbin User since: 04/13/03

RE: AND

Postby Quade » Wed Aug 21, 2002 3:30 pm

Well, all the RE is case independent so, it doesn't matter what case you're using. I was hoping Dexter would answer since he's more of an RE expert than I am.

My own thought is that RE's too much for most people. I'm thinking the default filtering should be like "The Bat" filtering.
User avatar
Quade
Eternal n00b
Eternal n00b
 
Posts: 44972
Joined: Sat May 19, 2001 12:41 am
Location: Virginia, US

Registered Newsbin User since: 10/24/97

RE: AND

Postby n4aof » Wed Jan 01, 2003 12:17 am

>My own thought is that RE's
>too much for most people.

AMEN!
User avatar
n4aof
Seasoned User
Seasoned User
 
Posts: 148
Joined: Sat Aug 17, 2002 10:38 pm

Registered Newsbin User since: 04/01/03

Postby bigbear » Mon Apr 28, 2003 7:13 pm

The case insensitive part of the question got answered, but the AND part didn't.

How can I create and expression that finds "foo" AND "bar" (without the quotes of course!). I know I can do "foo|bar", which would find anything that had "foo" OR "bar".

Is there an AND operator in RegEx?
bigbear
n00b
n00b
 
Posts: 9
Joined: Sun Apr 27, 2003 1:57 pm

Registered Newsbin User since: 05/02/03

Postby kewakl » Mon Apr 28, 2003 10:04 pm

bigbear wrote:Is there an AND operator in RegEx?


Do not think so in NewsBin's implementation.
Goto http://www.newsbin.com/nb33help/regexp.htm for a bit of Regex info.
Dex still hasn't fixed the link listed in http://forums.newsbin.com/viewtopic.php?t=4322
It includes the period at the end of the sentence--so your browser will return a page not found error.
User avatar
kewakl
Seasoned User
Seasoned User
 
Posts: 855
Joined: Sat May 26, 2001 7:26 pm
Location: Way Out There - Even farther now!

Registered Newsbin User since: 04/01/03

Postby Smite » Tue Apr 29, 2003 1:50 am

For now you can do foo and bar like so:
(foo.*bar)|(bar.*foo)
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 kewakl » Tue Apr 29, 2003 6:24 am

Smite wrote:For now you can do foo and bar like so:
(foo.*bar)|(bar.*foo)


Yeah, but that performs an 'OR' operation.
User avatar
kewakl
Seasoned User
Seasoned User
 
Posts: 855
Joined: Sat May 26, 2001 7:26 pm
Location: Way Out There - Even farther now!

Registered Newsbin User since: 04/01/03

Postby bigbear » Tue Apr 29, 2003 11:50 am

[quote="kewakl"][quote="Smite"]For now you can do foo and bar like so:
(foo.*bar)|(bar.*foo)[/quote]

Yeah, but that performs an 'OR' operation.[/quote]

That expression does *exactly* what I want. I haven't figured out the RegEx logic and why it works, but call it what you will (tomayto/ tomahto), it does work!

Thanks to all who participated.
bigbear
n00b
n00b
 
Posts: 9
Joined: Sun Apr 27, 2003 1:57 pm

Registered Newsbin User since: 05/02/03

Postby Smite » Wed Apr 30, 2003 3:19 am

Sure it performs an or, but any logic expression can be represented using only the not, or, and umm, I forget the other one, maybe conditional.. :P

Anyhow, that's really here nor there.

If a string contains A and B, it will either contain A followed sometime later by B, or by B followed sometime later by A. That's what that RegEx checked for.
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 kewakl » Thu May 01, 2003 12:51 am

Smite wrote:Sure it performs an or, but any logic expression can be represented using only the not, or, and umm, I forget the other one, maybe conditional.. :P

Anyhow, that's really here nor there.

If a string contains A and B, it will either contain A followed sometime later by B, or by B followed sometime later by A. That's what that RegEx checked for.


And when I unplugged my head from my.... I read the post and realized that! :oops:
User avatar
kewakl
Seasoned User
Seasoned User
 
Posts: 855
Joined: Sat May 26, 2001 7:26 pm
Location: Way Out There - Even farther now!

Registered Newsbin User since: 04/01/03

Postby bagera » Sun Jun 15, 2003 2:54 am

so:
d.*r.*u.*n.*k
Will filter out drunk, d-r-u-n-k, d_r_u_n_k

life as a spammer
employer: What's yur typing speed?

spammer applicant: I c-a-n t-y-p-e

employer: In your portfolio here. What would you say that tattoo of the knife thru your moms head represents?
User avatar
bagera
Occasional Contributor
Occasional Contributor
 
Posts: 29
Joined: Sat Mar 15, 2003 1:17 am

Postby Smite » Sun Jun 15, 2003 4:55 am

d.*r.*u.*n.*k will also match:
"Devilish parties are the brunt of many heavenly pranks."

So be carefull how you use that .*
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 bagera » Sun Jun 15, 2003 5:05 pm

How could make it more fool.*proof

Spose I could just add all the variables.
drunk|d-r-u-n-k|d_r_u_n_k|d,r,u,n,k

life as a spammer continued
spammer applicant: I have a knife for every $#%&#*& who doesn't appreciate my generous contributions to usernet. Ahh my mom wouldn't buy my p0rn so I axed her why.
User avatar
bagera
Occasional Contributor
Occasional Contributor
 
Posts: 29
Joined: Sat Mar 15, 2003 1:17 am

Postby Smite » Sun Jun 15, 2003 5:31 pm

Well, if you expect a single extra character between each character, you could just use d.r.u.n.k
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 bagera » Sun Jun 15, 2003 5:33 pm

d[^a-z]r[^a-z]u[^a-z]n[^a-z]k
d[a-z]r[a-z]u[a-z]n[a-z]k

Will this work does this constrain the filter to one word?
Is a space considered a character will this get d r u n k?
Thanks smite I like yours better.

I keep visiting http://www.newsbin.com/nb33help/regexp.htm
and it's a real handy page however it could use some practical appications for us technically challenged.

Perhapse some pre built filters to cut and paste into NBPro. with explanations on why they work. Or they could be included in NBPro similar to the mail merge fields. Wow I'm on a roll here. When can you implement that and wheres my fee for this incredible new feature.
User avatar
bagera
Occasional Contributor
Occasional Contributor
 
Posts: 29
Joined: Sat Mar 15, 2003 1:17 am

Once again,

Postby Quasi » Mon Apr 02, 2007 4:18 pm

Once again, you guys are my heros. I've been trying to figure out how to search for certain titles (alt.bin.e-book.tec) while excluding all of what I wasn't looking for. ie, introduction books for geometry. Now, with the above post, I can do that!

Thanks again for the help and the great product.
Quasi
Active Participant
Active Participant
 
Posts: 93
Joined: Sun Aug 01, 2004 2:24 pm

Registered Newsbin User since: 08/02/04

Postby bobkoure » Wed Apr 04, 2007 12:28 am

If you're interested in learning regular expressions, another good place to look is Links not allowed for unregistered users.
If you use a text editor that supports it, it becomes a lot easier to learn (you can see what you're doing) but (assuming you need to manipulate text) is incredibly useful.
bobkoure
 


Return to Regular Expressions

Who is online

Users browsing this forum: No registered users and 2 guests