CodeGrabber
{ USER }
posts: 23
last: 28-Apr-2008
TITLE: Splitting a space comma and semi colon separated list
DESCRIPTION: Java RegEx - Splitting a space-, comma-, and semi-colon separated list
Submitted: 28-Nov-2007 04:39:06 ( 1yrs 5w 6d 3h ago ) Language: REGEX (*.)
Views: 282 Lines of Code: 15 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Intermediate
Bookmark
//Java: RegEx: Splitting a space-, comma-, and semi-colon separated list

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