From: Chris Causer Date: 2008-10-21T00:16:25+09:00 Subject: Re: Way to split a string based on fixed length? ------=_Part_124359_9120470.1224515850127 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Oct 20, 2008 at 4:04 PM, Craig Demyanovich wrote: > I thought String#split with a regex might do it, but I'm not sure why it > returns an array with empty strings in it. > [snip] > >> '0000000N0000000N0000000N0000000N'.split(/(\w{8})/) > => ["", "0000000N", "", "0000000N", "", "0000000N", "", "0000000N"] Going a bit off topic here, but I suspect the reason split adds empty strings is because it is matching the 8 characters, splitting there, but because you are capturing them, puts the delimiter back in the array it as well. The gap between the 8 characters is nothing, thus "". I guess that if you split(/\w{8}/) you'll get nothing because there will be nothing left after removing the delimeter (unless the string isn't of length 8n, n is an integer.) ------=_Part_124359_9120470.1224515850127--