Logo

Programming-Idioms

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

Idiom #259 Split on several separators

Build the list parts consisting of substrings of the input string s, separated by any of the characters ',' (comma), '-' (dash), '_' (underscore).

parts = s.split( Regexp.union(",", "-", "_") )

Regexp.union takes care of escaping the "-".
var parts = s.Split(',', '-', '_');

New implementation...
< >
programming-idioms.org