日期:2014-05-20 浏览次数:20702 次
import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class TestRE { public static void main(String [] args){ String sSourceStr = "jerry,98|tom,99|jack,10|anne,100"; List<String> listStr = new ArrayList<String>(); List<Integer> listInt = new ArrayList<Integer>(); Pattern pStr = Pattern.compile("[a-zA-Z]+"); Pattern pInt = Pattern.compile("[0-9]+"); Matcher mStr = pStr.matcher(sSourceStr); Matcher mInt = pInt.matcher(sSourceStr); while(mStr.find()){ listStr.add(mStr.group()); } while(mInt.find()){ listInt.add(Integer.valueOf(mInt.group())); } String [] str = new String[listStr.size()]; int [] iInt = new int[listInt.size()]; str =listStr.toArray(str); for(int b=0;b<listInt.size();b++){ iInt[b] = listInt.get(b); } for(String s:str){ System.out.print(s+" "); } for(int i : iInt){ System.out.print(i+" "); } } }