Skip to content

Instantly share code, notes, and snippets.

@ELLIOTTCABLE
Created August 5, 2008 00:23
Show Gist options
  • Save ELLIOTTCABLE/3998 to your computer and use it in GitHub Desktop.
Save ELLIOTTCABLE/3998 to your computer and use it in GitHub Desktop.
string = '0123456789' * 3
# => "012345678901234567890123456789"
string.scan(/.{1,10}/)
# => ["0123456789", "0123456789", "0123456789"]
string2 = 'The quick blue merle Tucker jumped over the mean black and white Jazz.'
# => "The quick blue merle Tucker jumped over the mean black and white Jazz."
string2.scan(/.{1,30}/)
# => ["The quick blue merle Tucker ju", "mped over the mean black and w", "hite Jazz."]
string2.scan(/.{1,30}\b/)
# => ["The quick blue merle Tucker ", "jumped over the mean black and", " white Jazz"]
string2.scan(/.{1,30}\b\s*/)
# => ["The quick blue merle Tucker ", "jumped over the mean black and ", "white Jazz"]
string.scan(/.{1,10}\b\s*/)
# => ["0123456789"]
string.scan(/.{1,10}\b?\s*/)
# => ["", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "0123456789", ""]
"".scan(/.{1,10}\b?\s*/)
# => [""]
"1".scan(/.{1,10}\b?\s*/)
# => ["1", ""]
"12".scan(/.{1,10}\b?\s*/)
# => ["12", ""]
"123".scan(/.{1,10}\b?\s*/)
# => ["123", ""]
"1234".scan(/.{1,10}\b?\s*/)
# => ["1234", ""]
"12345".scan(/.{1,10}\b?\s*/)
# => ["12345", ""]
"123456".scan(/.{1,10}\b?\s*/)
# => ["123456", ""]
"1234567".scan(/.{1,10}\b?\s*/)
# => ["1234567", ""]
"12345678".scan(/.{1,10}\b?\s*/)
# => ["12345678", ""]
"123456789".scan(/.{1,10}\b?\s*/)
# => ["123456789", ""]
"1234567890".scan(/.{1,10}\b?\s*/)
# => ["1234567890", ""]
"12345678901".scan(/.{1,10}\b?\s*/)
# => ["", "2345678901", ""]
"123456789012".scan(/.{1,10}\b?\s*/)
# => ["", "", "3456789012", ""]
"1234567890123".scan(/.{1,10}\b?\s*/)
# => ["", "", "", "4567890123", ""]
"12345678901234".scan(/.{1,10}\b?\s*/)
# => ["", "", "", "", "5678901234", ""]
"123456789012345".scan(/.{1,10}\b?\s*/)
# => ["", "", "", "", "", "6789012345", ""]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment