From: William James Date: 2005-08-18T16:31:15+09:00 Subject: Re: Novice Q: What's the difference between /\s*/ and /(\s)*/? Mike Meng wrote: > # code > line = '/jazz/j00319.mp3 | 2:58 | Louis Armstrong | Wonderful World' > file, duration, artist, title = line.chomp.split(/\s*\|\s*/) > # code end > > Run the code we get: > file=='/jazz/j00319.mp3' > duration=='2:58' > artist=='Louis Armstrong' > title=='Wonderful World' > > While if I change the regex pattern in 'split' to /(\s)*\|(\s)*/, > that is, > # code > line = '/jazz/j00319.mp3 | 2:58 | Louis Armstrong | Wonderful World' > file, duration, artist, title = line.chomp.split(/(\s)*\|(\s)*/) > # code end > > We get: > file=='/jazz/j00319.mp3' > duration==' ' > artist==' ' > title=='2:58' > > What makes the differece? Any comments are appreciated. Without the captures, the substrings on which the string is split are discarded. When you include captures, they are included in the resulting array. Which makes sense: why would you include captures if you didn't want to do something with them?