From: mortee Date: 2007-11-01T15:17:24+09:00 Subject: Re: String#split and groups in the field separator RE Daniel Sheppard wrote: > Yes, any capture groups in the regex will be included in the split > array. If you want to use groups without capturing it into the split > array, use a non-capturing group - ie, /(?=,)/ rather than /(,)/ > > It is curious that it's not in the api doc... I must have learnt it from > somewhere... 7stud -- wrote: > I guess I should mention that the rule I jotted down in the margin of my > book is: if the split() pattern has parenthesized sub groupings, the > result array will include the match for each subgroup--but not the whole > match. > > Applying that rule to your examples: > >> irb(main):060:0> s.split(/(:)+/) >> => ["a", ":", "b", ":", "c", ":", "d"] => ? > > The subgroup (:) matches a single colon, so those matches are included > in the results, [...] Thanks, that clarifies it, and the results make sense based on the rule. However, I find it quite confusing to have parts of what I intend to be part of the "separator" among the list of results. To say the least. mortee