Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > how to use variable in a regular expression

Reply
Thread Tools

how to use variable in a regular expression

 
 
junkone@rogers.com
Guest
Posts: n/a
 
      07-19-2006
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

 
Reply With Quote
 
 
 
 
Jeff Pritchard
Guest
Posts: n/a
 
      07-19-2006
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/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Use variable in regular expression CarpeSkium@gmail.com Python 5 08-02-2007 01:32 PM
Set a variable from a substring of another variable using Regular Expression Tony Perl Misc 2 04-20-2005 11:57 PM
How to use backreferences in a variable for a regular expression Mark Fletcher Perl 1 05-19-2004 11:12 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments