Java: RegEx: Splitting A Space-, Comma-, And Semi-colon Separated List
Join the DZone community and get the full member experience.
Join For Free// Greedy RegEx quantifier used
// X+ = X, one or more times
// [\\s,;]+ = one or more times of either \s , or ;
String test_data = "hello world, this is a test, ;again";
_logger.debug("Source: " + test_data);
for (String tag : test_data.split("[\\s,;]+"))
{
_logger.debug("Received tag: [" + tag + "]");
}
Java (programming language)
Opinions expressed by DZone contributors are their own.
Comments