Pars & Rars Only

Tips on writing regular expressions for searching the post list

Moderators: Quade, dexter

Pars & Rars Only

Postby Vastlee » Sat Nov 26, 2005 2:55 am

Can anyone see a problem with what I have here? I don't currently, but I'd like to make sure there are no glaring holes. This 'should' show only pars & rars, unless I'm mistaken. TIA

.*\.[rR|pP][0-9|a-z|A-Z][0-9|a-z|A-Z]2?
Vastlee
Occasional Contributor
Occasional Contributor
 
Posts: 11
Joined: Wed May 05, 2004 12:12 pm

Registered Newsbin User since: 05/31/05

Postby Smite » Sat Nov 26, 2005 3:20 am

"Show any subjects that contains:
anything, or nothing
followed by a .
then by a r, R, |, p, or P
then by a 0,1,...,9,|,a,b,...,z,|,A,B,..., or Z
then by a 0,1,...,9,|,a,b,...,z,|,A,B,..., or Z
then by a 2, or not."


so ".|||" would pass, as would ".rQ5" and even "this.show.makes.me.want.to.puke"

if you want "only rar or par", I'd stick with something simple like:
\.[rp][a0-9][r0-9]
it's still match something like "this.is.my.parting.gift" but at least it's a lot more limiting than what you had before.
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 Quade » Sat Nov 26, 2005 12:18 pm

I typically assume a space or end of line at the end of the PAR extension so, I add a whitespace or end of line tag to the end of the RE.

"\.[r-z][a0-9][r0-9](\s|"|$)"

Still some buttwipes post with text hanging right off the extension but, it's somewhat rare. The RE's are case independent so, you don't have to worry about upper and lower case.
User avatar
Quade
Eternal n00b
Eternal n00b
 
Posts: 44981
Joined: Sat May 19, 2001 12:41 am
Location: Virginia, US

Registered Newsbin User since: 10/24/97

Postby Vastlee » Sun Nov 27, 2005 7:41 pm

I didn't realize that case wasn't an issue. I guess I can take the A-Z's out. Also, I thought that putting the brackets [] meant that was for a single digit? So that a[b]c could only equal abc not abbbbc. How does one specify that the enclosed items are meant to be single character only?
Vastlee
Occasional Contributor
Occasional Contributor
 
Posts: 11
Joined: Wed May 05, 2004 12:12 pm

Registered Newsbin User since: 05/31/05

Postby Quade » Sun Nov 27, 2005 8:12 pm

Well, a single character by itself will only match on itself. So,

"abc" and "a[b]c" are the same.

"a[a-z]c" would match "aac","abc"... up to "azc"

I only use [] for literals I might have to normally escape like "[.]" since "." by itself means match any char
User avatar
Quade
Eternal n00b
Eternal n00b
 
Posts: 44981
Joined: Sat May 19, 2001 12:41 am
Location: Virginia, US

Registered Newsbin User since: 10/24/97

Postby Vastlee » Sun Nov 27, 2005 8:17 pm

"a[a-z]c" would match "aac","abc"... up to "azc"

Right, that's what I thought, but from what I understood from the poster above a[b-c]d could equal abc,acd, abcd, acbd, or abbbbccccd. I 'thought' that a[b-c]d could only equate to abc,acd, abcd, acbd not multiples between it.
Vastlee
Occasional Contributor
Occasional Contributor
 
Posts: 11
Joined: Wed May 05, 2004 12:12 pm

Registered Newsbin User since: 05/31/05

Postby Smite » Sun Nov 27, 2005 8:20 pm

Vastlee wrote:from what I understood from the poster above a[b-c]d could equal abc,acd, abcd, acbd, or abbbbccccd.


Not sure where you got that idea. I certainly said nothing of the sort. Just glad you have it figured out now.
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 Vastlee » Sun Mar 11, 2007 3:40 am

The pipe symbol | means or in regex doesn't it? It's my understanding that [r|p] means a single digit that could be an r or p but nothing else. Please correct me if I am wrong, and also if I am wrong how would you do the previous stated or.
Vastlee
Occasional Contributor
Occasional Contributor
 
Posts: 11
Joined: Wed May 05, 2004 12:12 pm

Registered Newsbin User since: 05/31/05

Postby Quade » Sun Mar 11, 2007 10:31 am

That's how I interpret it.
User avatar
Quade
Eternal n00b
Eternal n00b
 
Posts: 44981
Joined: Sat May 19, 2001 12:41 am
Location: Virginia, US

Registered Newsbin User since: 10/24/97

Postby Smite » Tue Mar 13, 2007 2:21 am

[rp] means a single character that could be an r or p but nothing else. The | is intended for use outside of single-character situations.
eg:
autobots|decepticons
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 » Thu Mar 15, 2007 1:31 pm

Yep - [r|p] means 'r' or '|' or 'p'.

Quade > I only use [] for literals I might have to normally escape...
I also often use [ ] to mean "space" for readability (so I don't bother in the "find" window).

BTW, if you find yourself with an editor that can do find/replace with regex you will be amazed at what you can do - so this is not at all a NBP-only skill that you are learning...
bobkoure
 


Return to Regular Expressions

Who is online

Users browsing this forum: No registered users and 2 guests