myvar = /G/
ie = Watir::IE.attach(:title, myvar)
will attach to a windo that has a G anywhere in its title
Paul
You want to store the regular expression in the variable, so I tried the
following and it works:
It may also be helpful to look at the Ruby Documentation (RDoc) for the
Regexp (Regular Expression) class.
http://www.ruby-doc.org/core/classes/Regexp.html
In addition to creating a regular expression using the /pattern/
notation, a few quick helpers from an interactive ruby (irb) session:
# a is a string
irb(main):001:0> a = "foofar"
=> "foofar"
# create a new regular expression, b, from the string in a
# this is the same as writing b = Regexp.new "foofar"
irb(main):002:0> b = Regexp.new a
=> /foofar/
# obtain the string between the / characters
irb(main):003:0> b.source
=> "foofar"
# the regular expression itself
irb(main):004:0> b
=> /foofar/
# a string representation of the regexp as you would expect to see it in
code
irb(main):005:0> b.inspect
=> "/foofar/"
# a different string representation of the regexp
irb(main):006:0> b.to_s
=> "(?-mix:foofar)"
Hope this helps,
Alex