Thanks for the response. Is there a way to do this without a regular
expression? To further explain, I want the program to be able to do any
kind of literal string replacement at runtime, except that case is
ignored. If I use a regular expression as the match string, then
certain characters could be interpreted in special, non-literal ways,
which is not what I want in this case.
Jamal
···
-----Original Message-----
From: Mark Van Holstyn [mailto:mvette13@gmail.com]
Sent: Monday, April 17, 2006 12:25 PM
To: ruby-talk ML
Subject: Re: Beginner gsub and ri questions
"DOG" =~ /dog/i
On 4/17/06, Jamal Mazrui <Jamal.Mazrui@fcc.gov> wrote:
How can I do a case-insensitive global substitution? Suppose, for
example, a string contained occurences of DOG, Dog, dog, and mistyped
dOg. I want every instance to be replaced by cat (without having to
test for each case permutation).
How can I generate a large text file containing all ri documentation
available on my system? I would like the topics to be in as logical
an
order as possible, and in alphabetical order otherwise. I would like
to
place a \r\n\f\r\n sepearater sequence between each topic.
Jamal
--
Mark Van Holstyn
mvette13@gmail.com
http://lotswholetime.com
I don't fully understand the situation when a regex would work. Could you
give me one?
-mark
···
On 4/17/06, Jamal Mazrui <Jamal.Mazrui@fcc.gov> wrote:
Thanks for the response. Is there a way to do this without a regular
expression? To further explain, I want the program to be able to do any
kind of literal string replacement at runtime, except that case is
ignored. If I use a regular expression as the match string, then
certain characters could be interpreted in special, non-literal ways,
which is not what I want in this case.
Jamal
-----Original Message-----
From: Mark Van Holstyn [mailto:mvette13@gmail.com]
Sent: Monday, April 17, 2006 12:25 PM
To: ruby-talk ML
Subject: Re: Beginner gsub and ri questions
"DOG" =~ /dog/i
On 4/17/06, Jamal Mazrui <Jamal.Mazrui@fcc.gov> wrote:
>
> How can I do a case-insensitive global substitution? Suppose, for
> example, a string contained occurences of DOG, Dog, dog, and mistyped
> dOg. I want every instance to be replaced by cat (without having to
> test for each case permutation).
>
> How can I generate a large text file containing all ri documentation
> available on my system? I would like the topics to be in as logical
an
> order as possible, and in alphabetical order otherwise. I would like
to
> place a \r\n\f\r\n sepearater sequence between each topic.
>
> Jamal
>
>
--
Mark Van Holstyn
mvette13@gmail.com
http://lotswholetime.com
--
Mark Van Holstyn
mvette13@gmail.com
http://lotswholetime.com
What you want here is to construct your regular expression properly, such as:
catmatch = %r{#{Regexp::escape(cat)}}i
stringval =~ catmatch
The Regexp::escape (ri it) will prevent your fears from coming true, here.
-austin
···
On 4/17/06, Jamal Mazrui <Jamal.Mazrui@fcc.gov> wrote:
Thanks for the response. Is there a way to do this without a regular
expression? To further explain, I want the program to be able to do any
kind of literal string replacement at runtime, except that case is
ignored. If I use a regular expression as the match string, then
certain characters could be interpreted in special, non-literal ways,
which is not what I want in this case.
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca