[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gsub and single quote issue

Raj Singh

3/24/2009 8:33:00 PM

a = " Ruby's gem "

puts a.gsub(/[']/, "") #=> 1. Rubys gem

puts a.gsub(/[']/, "'") #=> 2. Ruby's gem

puts a.gsub(/[']/, "\'") #=> 3. Ruby's gem

puts a.gsub(/[']/, "\\'") #=> 4. Rubys gem s gem

puts a.gsub(/[']/, "\\\'") #=> 5. Rubys gem s gem

puts a.gsub(/[']/, "\\\\'") #=> 6. Ruby\'s gem

puts " "


I couldn't understand the result for #4 and #5. Any explanation is
appreciated.
--
Posted via http://www.ruby-....

5 Answers

Robert Klemme

3/24/2009 9:13:00 PM

0

On 24.03.2009 21:32, Raj Singh wrote:
> a = " Ruby's gem "
>
> puts a.gsub(/[']/, "") #=> 1. Rubys gem
>
> puts a.gsub(/[']/, "'") #=> 2. Ruby's gem
>
> puts a.gsub(/[']/, "\'") #=> 3. Ruby's gem
>
> puts a.gsub(/[']/, "\\'") #=> 4. Rubys gem s gem
>
> puts a.gsub(/[']/, "\\\'") #=> 5. Rubys gem s gem
>
> puts a.gsub(/[']/, "\\\\'") #=> 6. Ruby\'s gem
>
> puts " "
>
>
> I couldn't understand the result for #4 and #5. Any explanation is
> appreciated.

The sequence \' in a replacement string is interpreted as the post
match. That's why you see the duplication. You'll see this nicely by
bracketing the replacement:

irb(main):012:0> a = " Ruby's gem "
=> " Ruby's gem "
irb(main):013:0> a.gsub /'/, "<\\'>"
=> " Ruby<s gem >s gem "

There is also pre match:

irb(main):014:0> a.gsub /'/, "<\\`>"
=> " Ruby< Ruby>s gem "

Kind regards

robert


--
remember.guy do |as, often| as.you_can - without end

7stud --

3/25/2009 5:19:00 AM

0

Robert Klemme wrote:
>
> The sequence \' in a replacement string is interpreted as the post
> match.
>

I assume that has something to do with ruby's crazy global variables,
e.g $'. In that case, why isn't the '$' required.

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

Robert Klemme

3/25/2009 7:07:00 AM

0

On 25.03.2009 06:18, 7stud -- wrote:
> Robert Klemme wrote:
>> The sequence \' in a replacement string is interpreted as the post
>> match.
>
> I assume that has something to do with ruby's crazy global variables,
> e.g $'. In that case, why isn't the '$' required.

The replacement string is interpreted by sub and gsub and this is just
the convention that was chosen. Btw, it's the same convention as in sed
and a number of other regular expression based replacement tools as well.

Kind regards

robert

bzlrbi

6/29/2011 9:41:00 PM

0

On Wed, 29 Jun 2011 14:33:37 -0700, "DGDevin"
<DGDevin@invalid.invalid> wrote:

>
>
>"band beyond description" wrote in message
>news:9713mfFkg9U1@mid.individual.net...
>
>> those guys (Budnick and Josh Baron) come from relix/jambands.com, so have
>> more than a clue...sounds like an interesting book, with insights into the
>> more modern seamy underside of the always distasteful music biz...
>
>I don't know why they even bother to print prices on ticket anymore
>considering they divert many tickets to resellers who will jack up the price
>and the public will never be able to buy those tickets at face value. For
>some events they don't have a price upfront, the new term is "dynamic
>pricing" which means it keeps going up until tickets stop selling.
>
>My wife and I just saw the Chris Robinson Brotherhood for the third time in
>the past few months, $20 each for a three-hour show with a certified big
>star front and center. They played "Brown Eyed Women" for the first time
>too, nailed it. So these bands that want us to pay hundreds of dollars each
>for a ninety-minute show can peddle their wares elsewhere.
Please tell us how many dollars you spent on the Stones their last
couple tours. Granted, their sets last 120 minutes.

DGDevin

7/1/2011 12:26:00 AM

0



wrote in message news:3s6n0754mdpfaodsoivqi613daea3u2spe@4ax.com...


> Please tell us how many dollars you spent on the Stones their last
> couple tours. Granted, their sets last 120 minutes.

LOL, with hotels and transportation factored in it must have been several
hundred dollars each for every show we went to, and that was a shitload of
shows. The Stones are one of two bands on earth we would do that for, The
Who being the other. I'm doubtful there will be further opportunities to
pay that kind of money (or any kind of money) for either of those acts.

I didn't say we've never paid silly money for live music, I said we've
stopped doing so. We've passed on a bunch of bands lately because their
ticket prices had just gone up too much, I'm not paying $150-200 bucks a
seat for someone we saw for a fraction of that just a couple of years ago.
So I'll claim to be only a little bit pregnant on the issue of encouraging
the bastards by buying their overpriced tickets.