Another regular expression question

T

tuyet.ctn

I have a select box that contains two items that are similar:
1) GICS Sector
2) Sector

How do tweak this command to select the second item "Sector" instead of
"GICS Sector"?

irb(main):065:0> ie.frame("customizeRemoteContent").select_list:)id,
"availableColumnsSelectBox").select(/Sector/)

This selects "GICS Sector"

I have tried select([Sector]) and other permutations but can't seem to
find the right one. I did go to this site to read up more about
regular expression, but the examples are not very clear. Appreciate
your suggestions!
http://www.ruby-doc.org/docs/ProgrammingRuby/html/intro.html#S5
 
T

Timothy Hunter

I have a select box that contains two items that are similar:
1) GICS Sector
2) Sector

How do tweak this command to select the second item "Sector" instead of
"GICS Sector"?

irb(main):065:0> ie.frame("customizeRemoteContent").select_list:)id,
"availableColumnsSelectBox").select(/Sector/)

This selects "GICS Sector"

I have tried select([Sector]) and other permutations but can't seem to
find the right one. I did go to this site to read up more about
regular expression, but the examples are not very clear. Appreciate
your suggestions!
http://www.ruby-doc.org/docs/ProgrammingRuby/html/intro.html#S5

Look for "anchors". The sequence "\A" matches the beginning of a string,
so the regular expression /\ASector/ will match only strings that start
with "Sector".

Similarly "\z" matches the end of a string.
 
T

tuyet.ctn

Thanks, Timothy, I did see this in the Ruby Regular Expression web
site, but when I tried it, I got an error:
irb(main):009:0> ie.frame("customizeRemoteContent").select_list:)id,
"availableColumnsSelectBox").select(/\ASector/)
Watir::Exception::NoValueFoundException: Selectbox was found, but
didn't find item with text of (?-mix:\ASector) from
C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3306:in
`select_item_in_select_list'
from C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3284:in `each'
from C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3284:in
`select_item_in_select_list'
from C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3261:in `select'
from (irb):9
from :0
 
K

Kelly Felkins

------=_Part_2751_22788975.1121242508075
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

I highly recommend these resources:

http://www.weitz.de/regex-coach/
This is a windows application that you can use to interactively build=20
regular expressions.

http://samuelfullman.com/team/php/tools/regular_expression_tester_p2.php
This is a web based regular expression tester.=20

-Kelly


=20
Thanks, Timothy, I did see this in the Ruby Regular Expression web
site, but when I tried it, I got an error:
irb(main):009:0> ie.frame("customizeRemoteContent").select_list:)id,
"availableColumnsSelectBox").select(/\ASector/)
Watir::Exception::NoValueFoundException: Selectbox was found, but
didn't find item with text of (?-mix:\ASector) from
C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3306:in
`select_item_in_select_list'
from C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3284:in `each'
from C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3284:in
`select_item_in_select_list'
from C:/ruby/lib/ruby/site_ruby/1.8/watir.rb:3261:in `select'
from (irb):9
from :0
=20
=20

------=_Part_2751_22788975.1121242508075--
 
L

Logan Capaldo

Thank you for your suggestions.
I was able to decipher what I need using the web based regular
expression tester you mentioned (I bookmarked it)
I also used this site to look up the different permutations that I can
use:
http://www.regular-expressions.info/quickstart.html
The right answer for what I need is:
/[^GICS Sector]Sector/

That's actually only a coincidence that that works. [ ] means match
one occurence of the characters inside the [ ]. [^ ] means match one
occurence of any character NOT between the [^ ]

Give it a shot by using SIGS Sector as an example string. It will
still match. Of course in this case its not that important since it
does what you need, however the correct regexp should be /^Sector/.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top