Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Java: RegEx: Splitting A Space-, Comma-, And Semi-colon Separated List

DZone's Guide to

Java: RegEx: Splitting A Space-, Comma-, And Semi-colon Separated List

·
Free Resource
// 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 + "]");
    }
Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}