Subsituting a character conditionally

M

Minkoo Seo

Hi group.

I'd like to substitute every quotation mark ` with whitespace. But, I
don't want to substitue "`" which is used for the purpose of
abbreviation.

Example>
I'm not a girl => I'm not a girl
`Hello world' => Hello world'

I've written the following for this purpose:

irb(main):003:0> s = "they can't prove I did `hello world'"
=> "they can't prove I did `hello world'"
irb(main):004:0> loc = (s =~ / `[a-z|A-Z]/)
=> 22
irb(main):005:0> s[loc + 1, 1] = ' '
=> " "
irb(main):006:0> s
=> "they can't prove I did hello world'"
irb(main):007:0>

But this seems to be unawkard because of loc = ( s =~ ...) which
contains seemingly two "="s. Is there another way to do this? If so,
please let me know.

Sincerely,
Minkoo Seo
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,206
Messages
2,571,068
Members
47,674
Latest member
scazeho

Latest Threads

Top