Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Lua

Idiom #283 Split with a custom string separator

Build the list parts consisting of substrings of input string s, separated by the string sep.

local function split(s,sep)
 local parts={}
 for sub in string.gmatch(s,"[^"..sep.."]+") do
  table.insert(parts,sub)
 end
 return parts
end
(def parts (clojure.string/split s sep))

ensure sep is a Regex

New implementation...