日期:2014-05-20 浏览次数:20836 次
String test = "张三\\李四\\王小二\\Thomas\\……\\唐"; Pattern p = Pattern.compile("(?<=^|\\\\)[^\\\\]+(?=\\\\|$)"); Matcher m = p.matcher(test); while(m.find()){ System.out.println(m.group()); }
------解决方案--------------------
import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String str=scanner.nextLine(); System.out.println(str); String[] strs = str.split("\\\\"); for(String temp:strs) System.out.println(temp); } }
------解决方案--------------------