[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

String#split "feature"

Gary Yngve

2/10/2009 8:20:00 PM

[Note: parts of this message were removed to make it a legal post.]

Just got bitten by some functionality of split w/ grouped patterns:

(in ruby 1.8.6...)
>> "foo bar baz".split(/bar/)
=> ["foo ", " baz"]
>> "foo bar baz".split(/(bar)/)
=> ["foo ", "bar", " baz"]

The 1.8 docs are silent on this, but the 1.9 docs at least say
"If pattern contains groups, the respective matches will be returned in the
array as well. "

This "feature" surprised the heck out of me.. Anyone know if this
functionality is intentional (from the enduser standpoint), or rather a
byproduct of implementation details?

Anyhoo, if anyone else gets weird behavior for string split including the
pattern, or with groups in the pattern, maybe you'll remember this or maybe
google will tell you about this.

Thanks,
-Gary

20 Answers

7stud --

2/10/2009 8:38:00 PM

0

Gary Yngve wrote:
>
> The 1.8 docs are silent on this, but the 1.9 docs at least say
> "If pattern contains groups, the respective matches will be returned in
> the
> array as well. "
>

pickaxe2 p.619:
=====
split
...
...
If pattern includes groups, these groups will be included in the
returned values.
...
=====


> This "feature" surprised the heck out of me.. Anyone know if this
> functionality is intentional (from the enduser standpoint), or rather a
> byproduct of implementation details?
>

It can be a really handy feature. python's regex split() function works
the same way.


> Anyhoo, if anyone else gets weird behavior for string split including
> the
> pattern, or with groups in the pattern, maybe you'll remember this or
> maybe
> google will tell you about this.
>
> Thanks,
> -Gary

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

Rob Biedenharn

2/10/2009 8:47:00 PM

0

On Feb 10, 2009, at 3:38 PM, 7stud -- wrote:

> Gary Yngve wrote:
>>
>> The 1.8 docs are silent on this, but the 1.9 docs at least say
>> "If pattern contains groups, the respective matches will be
>> returned in
>> the
>> array as well. "
>>
>
> pickaxe2 p.619:
> =====
> split
> ...
> ...
> If pattern includes groups, these groups will be included in the
> returned values.
> ...
> =====

Interestingly, this feature is described in String#scan, but the ri
docs for my Apple-provided ruby do not have the sentence for
String#split.

$ ruby -v
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]

-Rob

>> This "feature" surprised the heck out of me.. Anyone know if this
>> functionality is intentional (from the enduser standpoint), or
>> rather a
>> byproduct of implementation details?
>>
>
> It can be a really handy feature. python's regex split() function
> works
> the same way.
>
>
>> Anyhoo, if anyone else gets weird behavior for string split including
>> the
>> pattern, or with groups in the pattern, maybe you'll remember this or
>> maybe
>> google will tell you about this.
>>
>> Thanks,
>> -Gary
>

Rob Biedenharn http://agileconsult...
Rob@AgileConsultingLLC.com



F. Senault

2/10/2009 10:14:00 PM

0

Le 10 février 2009 à 21:20, Gary Yngve a écrit :

> This "feature" surprised the heck out of me.. Anyone know if this
> functionality is intentional (from the enduser standpoint), or rather a
> byproduct of implementation details?
>
> Anyhoo, if anyone else gets weird behavior for string split including the
> pattern, or with groups in the pattern, maybe you'll remember this or maybe
> google will tell you about this.

It's quite useful. Note that you can always use non-capturing groups
(the (?:expr) construct) if you don't want them :

>> "one, two and three".split(/\s*(and|or|,)?\s+/)
=> ["one", ",", "two", "and", "three"]

>> "one, two and three".split(/\s*(?:and|or|,)?\s+/)
=> ["one", "two", "three"]

Fred
--
Stick it to them like a phoenix rise
There's nothing grander than the big surprise
They can't hurt you with their sticks and stones (Garbage, Right
About time take them right between the eyes Between the Eyes)

kpnnews@yahoo.com

3/16/2011 4:03:00 PM

0

On Mar 16, 11:43 am, "sweetbac" <sweet...@sbcglobal.net> wrote:
> "Sneakerface" <n...@earthlink.net> wrote in message
> > You Never Give Me Your Money>
> > Sun King>
> > Mean Mr. Mustard>
> > Polythene Pam>
> > Bathroom Window>
> > Golden Slumbers>
> > Carry That Weight>
> > The End
> > Built to Last
> > Truckin'
>
> I'm sure Phils rendition of "Mean Mr. Mustard" was epic.
> <stares>
> This is embarrassing.

I will admit that I am curious although I am going in with very low
expectations.

One that is not embarrassing:
http://en.wikipedia.org/wiki/The_Other_Side_of_...

Kurt

volkfolk

3/16/2011 9:35:00 PM

0

On Mar 16, 12:03 pm, gringo <kpnn...@yahoo.com> wrote:
> On Mar 16, 11:43 am, "sweetbac" <sweet...@sbcglobal.net> wrote:
>
> > "Sneakerface" <n...@earthlink.net> wrote in message
> > > You Never Give Me Your Money>
> > > Sun King>
> > > Mean Mr. Mustard>
> > > Polythene Pam>
> > > Bathroom Window>
> > > Golden Slumbers>
> > > Carry That Weight>
> > > The End
> > > Built to Last
> > > Truckin'
>
> > I'm sure Phils rendition of "Mean Mr. Mustard" was epic.
> > <stares>
> > This is embarrassing.
>
> I will admit that I am curious although I am going in with very low
> expectations.
>
> One that is not embarrassing:http://en.wikipedia.org/wiki/The_Other_Side_of_...
>
> Kurt

I like "White Rabbit" too. George is awesome

Scot

Dave Kelly

3/16/2011 10:46:00 PM

0


"Ray O'Hara" <raymond-ohara@hotmail.com> wrote in message

> yes, don't they understand they are supposed to just perform old records.
> "new songs" apostasy!, it must be stopped.

The frickin' Beatles barely pulled off that rekkid.
You telling me Jethro from DSO and Sunshine Becker
et al outdid the Fabs, Raymundo?
Amazing.
Now run along....and where's my G'damn LL Bean catalogue?


Michael Turner

3/16/2011 11:01:00 PM

0

On Mar 16, 3:46 pm, "sweetbac" <sweet...@sbcglobal.net> wrote:
> "Ray O'Hara" <raymond-oh...@hotmail.com> wrote in message
> > yes, don't they understand they are supposed to just perform old records.
> > "new songs" apostasy!, it must be stopped.
>
> The frickin' Beatles barely pulled off that rekkid.
> You telling me Jethro from DSO and Sunshine Becker
>  et al outdid the Fabs, Raymundo?
> Amazing.
> Now run along....and where's my G'damn LL Bean catalogue?

The show looks really solid in my book. And they pulled off the Abbey
Road Medley extremely well. The jam into The End gave me chills.
John, Jeff P and Sunshine really stepped up to the plate to help the
boys pull this off, and Jeff C was outstanding as always.

Neil X

3/17/2011 3:58:00 AM

0

On Mar 16, 7:00 pm, Michael Turner <Michael112...@yahoo.ca> wrote:
> On Mar 16, 3:46 pm, "sweetbac" <sweet...@sbcglobal.net> wrote:
>
> > "Ray O'Hara" <raymond-oh...@hotmail.com> wrote in message
> > > yes, don't they understand they are supposed to just perform old records.
> > > "new songs" apostasy!, it must be stopped.
>
> > The frickin' Beatles barely pulled off that rekkid.
> > You telling me Jethro from DSO and Sunshine Becker
> >  et al outdid the Fabs, Raymundo?
> > Amazing.
> > Now run along....and where's my G'damn LL Bean catalogue?
>
> The show looks really solid in my book.  And they pulled off the Abbey
> Road Medley extremely well.  The jam into The End gave me chills.
> John, Jeff P and Sunshine really stepped up to the plate to help the
> boys pull this off, and Jeff C was outstanding as always.


Uh, well, you're arguing with someone who is way to evolved to have
actually listened to the music in question. Just FYI.

Peace,
Neil X.

Dave Kelly

3/17/2011 4:19:00 AM

0


"Neil X" <neilxk@yahoo.com> wrote in message
>
> > The frickin' Beatles barely pulled off that rekkid.
> > You telling me Jethro from DSO and Sunshine Becker
> > et al outdid the Fabs, Raymundo?
> > Amazing.
> > Now run along....and where's my G'damn LL Bean catalogue?


> Uh, well, you're arguing with someone who is way to evolved
> to have actually listened to the music in question. Just FYI.

> Peace,
> Neil X.

Exactly.
I cant stand it when the lurker kids come outta the
shadows and pontificating like that!
Disgusted.


Rupert

3/17/2011 5:02:00 AM

0

Ya know, every one here has their own opinions, and you know what you
like. And I have to admit I really want to like Furthur, I really do.
I've downloaded some soundboards off Demonoid, and even burned some to
disc and listened to them in the car, hoping they might grow on me,
and I've promptly deleted them all. I just don't feel it. Maybe I
missed a memo. Everything seems to be at half speed, like Bobby's
typical lounge rock act. Ratdog actually rocked harder. The back-up
singers don't fuckin' help. It sounds like Cache Creek Casino. I just
listened to the Abbey Road show from last night and I just don't see
the draw. It was reminiscent of the Moody Blues show I saw between the
pledge breaks the other night. Just kind of sad.

Every time John Kawhatsisname opens his mouth to sing, I cringe.
Especially when he's singing Jerry's parts. The man gets an "A" for
effort, but I just don't think he can sing. I loved the stuff that
Phil was doing with his own band, with the possible exception of the
whole Scofield fiasco, and the fact that they rarely let Barry Sless
play anything other than pedal steel, but I just can't get into this.

I'll stick with David Nelson Band shows. They cost one-third the
price, and they rock ten times as much.