Logo

Programming-Idioms

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

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).

my @parts = split(/[,\-_]/, $s);

Technically, the - (dash) does not need to be escaped here since it is not representing a range. However, it is a good habit and will lead to less confusion to escape it.
using System.Text.RegularExpressions;
var parts = Regex.Split(s, "[,_-]");

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