F. Senault
2/10/2009 10:14:00 PM
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)