how to use variable in a regular expression

J

junkone

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
 
J

Jeff Pritchard

unknown said:
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
 

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,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top