Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
regular expression
#18
Solved: 11 Years, 3 Months, 4 Weeks ago
Code:
(Junk)$|Junk[\d\)\(]+
To break this one down, we first start with the pipe operator "|" which means "or". So we'll take the left expression first.
Code:
(Junk)$
"$" means "end of input". So, the left side means: match the text "Junk" with no characters after it.
Code:
Junk[\d\)\(]+
On the right side, you have the brackets "[]" which denotes a character class. Each character inside it is a "legal" match for the character after the text "Junk". The characters included are "\d" which denotes any digit, "\)" which matches the character ")", and "\(" which matches the character "(". You have to escape parenthesis since they are operators in regular expressions. So, add the "+" to the character class, which will match either parenthesis and any digit, and it means match any one of those three characters one or more times. That's why I didn't think that expression was the best way to do it. It would also match something like "Junk)))234(()234(676767)(((((660"

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.
Reply


Messages In This Thread
regular expression - by bangla123 - 10-06-2010, 12:30 AM
RE: regular expression - by jsknight1969 - 10-06-2010, 12:39 AM
RE: regular expression - by bangla123 - 10-06-2010, 12:46 AM
RE: regular expression - by jsknight1969 - 10-06-2010, 12:52 AM
RE: regular expression - by bangla123 - 10-06-2010, 12:52 AM
RE: regular expression - by jsknight1969 - 10-06-2010, 01:02 AM
RE: regular expression - by bangla123 - 10-06-2010, 01:06 AM
RE: regular expression - by jsknight1969 - 10-06-2010, 01:16 AM
RE: regular expression - by bangla123 - 10-06-2010, 01:26 AM
RE: regular expression - by Pallavii - 10-06-2010, 02:37 PM
RE: regular expression - by bangla123 - 10-06-2010, 10:34 PM
RE: regular expression - by cdesserich - 10-07-2010, 01:07 AM
RE: regular expression - by bangla123 - 10-07-2010, 08:52 PM
RE: regular expression - by jsknight1969 - 10-06-2010, 01:37 AM
RE: regular expression - by bangla123 - 10-06-2010, 02:08 AM
RE: regular expression - by cdesserich - 10-06-2010, 04:17 AM
RE: regular expression - by bangla123 - 10-06-2010, 09:13 PM
RE: regular expression - by cdesserich - 10-08-2010, 09:35 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Any digit in xpath path using Regular expression Priyam 1 3,495 10-05-2016, 11:05 AM
Last Post: Ankur
  Regular expression to read two words in lowercase, uppercase and with and without spa sarahq49 1 3,361 04-09-2015, 01:56 AM
Last Post: sarahq49
  Regular expression and script optimisation Padmavathy 1 3,830 03-30-2015, 11:46 AM
Last Post: supputuri
  Regular expression in descriptive programming testernc 1 16,576 12-08-2014, 06:38 PM
Last Post: anshika.agarwal
  need a regular expression. anu05446 0 3,123 11-26-2014, 03:00 PM
Last Post: anu05446

Forum Jump:


Users browsing this thread: 8 Guest(s)