Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Java: RegEx: Splitting a space-, comma-, and semi-colon separated list (See related posts)

// 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 + "]");
    }

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts