how to use variable in a regular expression

Discussion in 'Ruby' started by junkone@rogers.com, Jul 19, 2006.

  1. Guest

    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
    , Jul 19, 2006
    #1
    1. Advertising

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

    --
    Posted via http://www.ruby-forum.com/.
    Jeff Pritchard, Jul 19, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Fletcher
    Replies:
    1
    Views:
    482
    Mark Fletcher
    May 19, 2004
  2. VSK
    Replies:
    2
    Views:
    2,272
  3. Replies:
    5
    Views:
    443
    Steve Holden
    Aug 2, 2007
  4. Tony
    Replies:
    2
    Views:
    120
    Tad McClellan
    Apr 21, 2005
  5. SamL
    Replies:
    6
    Views:
    147
    Ted Zlatanov
    Mar 25, 2009
Loading...

Share This Page