Logo

Programming-Idioms

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

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
using System.Text.RegularExpressions;
var parts = Regex.Split(s, "[,_-]");
var parts = s.Split(',', '-', '_');
var parts = s.split( RegExp(r"[,-_]") );
import "regexp"
re := regexp.MustCompile("[,\\-_]")
parts := re.Split(s, -1)
var parts = s.split(/[-_,]/)
import static java.util.Collections.list;
import java.util.List;
import java.util.StringTokenizer;
List<?> parts = list(new StringTokenizer(s, ",-_"));
import static java.util.regex.Pattern.quote;
String parts[] = s.split("[%s]".formatted(quote(",-_")), -1);
import static java.util.regex.Pattern.quote;
import java.util.Scanner;
Scanner t = new Scanner(s);
t.useDelimiter("[%s]".formatted(quote(",-_")));
String list[] = t.tokens().toArray(String[]::new);
t.close();
uses sysutils;
parts := s.split([',','_','-']);
my @parts = split(/[,\-_]/, $s);
import re
parts = re.split('[,_\-]', s)
import re
z = ',-_'
p = f'[{re.escape(z)}]'
parts = re.split(p, s)
parts = s.split( Regexp.union(",", "-", "_") )
let parts: Vec<_> = s.split(&[',', '-', '_'][..]).collect();