# Regular exressions and arguments

**URL:** <https://www.ruby-forum.com/t/regular-exressions-and-arguments/155965>\
**Category:** Ruby\
**Created:** [December 18, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/regular-exressions-and-arguments/155965 "2008-12-18T16:40:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ukbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/898d66/32.png) [@ukbell](https://www.ruby-forum.com/u/ukbell)\
**Post date:** [December 18, 2008, 4:40pm UTC](https://www.ruby-forum.com/t/regular-exressions-and-arguments/155965/1 "2008-12-18T16:40:29Z")

</div>

This should be (and probably will be) a simple answer, but if I have the  
very basic program of:

#!/usr/bin/ruby

require

arg = ARGV[0]  
regex = /"#{arg}"/  
regex1 = /Test/

a = “this is a Test”

if regex =~ a  
puts “test works”  
else  
puts “test isn’t working”  
end

With this code, if i inputs ./filename ‘Test’, how can i get the regex  
to be correct? I can only think of using the “#{}” to put this inside  
the expression, but this puts the parenthesis around it…

---

<div class="post-metadata">

**Author:** ![ukbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/898d66/32.png) [@ukbell](https://www.ruby-forum.com/u/ukbell)\
**Post date:** [December 18, 2008, 4:47pm UTC](https://www.ruby-forum.com/t/regular-exressions-and-arguments/155965/2 "2008-12-18T16:47:23Z")

</div>

Should have just waited a little longer… figured it out… needed to  
use the a = Regex.new(ARGV[0]) command to make it work… Thanks any way  
every one.

---

<div class="post-metadata">

**Author:** ![ukbell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/898d66/32.png) [@ukbell](https://www.ruby-forum.com/u/ukbell)\
**Post date:** [December 18, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/regular-exressions-and-arguments/155965/3 "2008-12-18T17:09:57Z")

</div>

On Thu, Dec 18, 2008 at 4:39 PM, Rick J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Should have just waited a little longer… figured it out… needed to  
> use the a = Regex.new(ARGV[0]) command to make it work… Thanks any way  
> every one.

You can also use the regex literal, but you need to lose the double  
quotes.  
Check this:

irb(main):001:0\> a = “Test”  
=\> “Test”  
irb(main):002:0\> re = /#{a}/  
=\> /Test/  
irb(main):003:0\> re = /“#{a}”/  
=\> /“Test”/

Hope this helps,

Jesus.
