DZone 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

Snippets has posted 5883 posts at DZone. View Full User Profile

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

08.05.2007
| 35280 views |
  • submit to reddit
        // 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 + "]");
    }