Need "=" to look like a strint

I have the following variable. Ruby looks at the = sign as a regex
literal and I need it to be recognized as text.

search_text =! %r{

···

=
}x

--
Posted via http://www.ruby-forum.com/.

ruby-1.8.7-p302 > pattern = %r{=}
=>
ruby-1.8.7-p302 > pattern.inspect
=> "/=/"
ruby-1.8.7-p302 > "abc=xyz" =~ pattern
=> 3

Maybe I'm not understanding your issue?

···

On Wed, Feb 2, 2011 at 10:19 AM, Bob Hatch <roberth@monavie.com> wrote:

I have the following variable. Ruby looks at the = sign as a regex
literal and I need it to be recognized as text.

search_text =! %r{

}x

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

You have a typo in your code sample here, and the message you see as a
result is:

warning: regex literal in condition

That is because of the =! you have. Ruby breaks that down into an
assigment (the = part) and a boolean negation (the ! part) of the
following regexp. You need to change the =! to just = as follows:

search_text = %r{

···

On 2/2/2011 12:19 PM, Bob Hatch wrote:

I have the following variable. Ruby looks at the = sign as a regex
literal and I need it to be recognized as text.

search_text =! %r{
  =
}x

  =
}

-Jeremy

I think he meant to use =~ instead.

···

On Wed, Feb 2, 2011 at 1:37 PM, Jeremy Bopp <jeremy@bopp.net> wrote:

On 2/2/2011 12:19 PM, Bob Hatch wrote:

I have the following variable. Ruby looks at the = sign as a regex
literal and I need it to be recognized as text.

search_text =! %r{

}x

You have a typo in your code sample here, and the message you see as a
result is:

warning: regex literal in condition

That is because of the =! you have. Ruby breaks that down into an
assigment (the = part) and a boolean negation (the ! part) of the
following regexp. You need to change the =! to just = as follows:

search_text = %r{

}

That's a possibility, but take a look at the conversations in recent
threads opened by Bob. You'll find that he's using this search_text
variable to hold a regexp in an ongoing series of problems he's running
into while writing a script to basically perform an fgrep operation on a
file. I actually suggested he try out this particular method for
specifying his regexp and assigning it to search_text, so I assumed he
ran into this problem while implementing that. :slight_smile:

-Jeremy

···

On 02/02/2011 09:50 PM, Eric Christopherson wrote:

On Wed, Feb 2, 2011 at 1:37 PM, Jeremy Bopp <jeremy@bopp.net> wrote:

On 2/2/2011 12:19 PM, Bob Hatch wrote:

I have the following variable. Ruby looks at the = sign as a regex
literal and I need it to be recognized as text.

search_text =! %r{
  =
}x

You have a typo in your code sample here, and the message you see as a
result is:

warning: regex literal in condition

That is because of the =! you have. Ruby breaks that down into an
assigment (the = part) and a boolean negation (the ! part) of the
following regexp. You need to change the =! to just = as follows:

search_text = %r{

}

I think he meant to use =~ instead.