Page 1 of 1

Pars & Rars Only

PostPosted: Sat Nov 26, 2005 2:55 am
by Vastlee
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?

PostPosted: Sat Nov 26, 2005 3:20 am
by Smite
"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.

PostPosted: Sat Nov 26, 2005 12:18 pm
by Quade
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.

PostPosted: Sun Nov 27, 2005 7:41 pm
by Vastlee
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?

PostPosted: Sun Nov 27, 2005 8:12 pm
by Quade
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

PostPosted: Sun Nov 27, 2005 8:17 pm
by Vastlee
"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.

PostPosted: Sun Nov 27, 2005 8:20 pm
by Smite
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.

PostPosted: Sun Mar 11, 2007 3:40 am
by Vastlee
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.

PostPosted: Sun Mar 11, 2007 10:31 am
by Quade
That's how I interpret it.

PostPosted: Tue Mar 13, 2007 2:21 am
by Smite
[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

PostPosted: Thu Mar 15, 2007 1:31 pm
by bobkoure
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...