import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @author ymo * */ public class Main { protected static Pattern wordToken; protected static Pattern lineToken; protected static String line = " , ,"; public static void main(String[] args) { lineToken = Pattern.compile("(.*)?(.*)?"); Matcher m = lineToken.matcher(line); // Create Matcher for (;m.find();) { String s = m.group(); if(s.length()!=0){ System.out.println(m.start()+":"+m.end()+":"+m.group()); } } } } --- 0:8: ,