How to use variable in a regular expression

HI
For ex i want to check for pattern variable in watir - Ruby and search
like following

pattern= ‘oo’
ie.button(:value, /pattern/i).click

How do i do it.

Seede

unknown wrote:

HI
For ex i want to check for pattern variable in watir - Ruby and search
like following

pattern= ‘oo’
ie.button(:value, /pattern/i).click

How do i do it.

Seede

use #{variable_name} inside the regexp

vis:
irb(main):018:0> fred = “bob”
=> “bob”
irb(main):019:0> " my name is fred flintsone" =~ /#{fred}/
=> nil
irb(main):020:0> “my name is bob bowden” =~ /#{fred}/
=> 11

best,
jp

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs