10-08-2010, 09:35 PM
Code:
(Junk)$|Junk[\d\)\(]+
Code:
(Junk)$
Code:
Junk[\d\)\(]+
So, (whew!) the expression says: match the text "Junk" with no characters after it OR match the text "Junk" with one or more characters after it that could be a digit, a left parenthesis, or a right parenthesis.
I explained the "Junk( \(\d+\))?" expression in my post, but I guess I wasn't perfectly clear on the question mark. The question mark means that the expression in the parenthesis grouping may or may not be there.
cdesserich Wrote:This expression says "click the link that has the text 'Junk' that may or may not be followed by the expression ' \(\d+\)' which says the text '<one space><one left parenthesis><one or more digits><one right parenthesis>'"
That's where I was confused before, I thought that when the junk folder was empty the link text would simply be "Junk". So the "Junk( \(\d+\))?" expression will match "Junk" or "Junk (<one or more digits>)". We needed an expression that matched "Junk (<zero or more digits>)" which is why "Junk \(\d*)\)" works. The "*" operator means "zero or more".
Please see Ankur's post about this subject, Regular Expressions Regularized, right here on this site! I have this post bookmarked and use it very frequently as a resource when figuring out regular expressions. There are other good tools out there as well. Another one I use is The RegEx Coach which is a program that helps visualize how regular expressions work. It is free, has great documentation, and good tutorials. Good Luck!
P.S. the email link at the bottom of my posts should work fine, but if questions are asked in a public forum like this, then everyone can benefit from the information shared. I am far from being an expert at regular expressions, I struggle with them a lot, like most people.