有一行文本格式如下
张三\李四\王小二\Thomas\……\唐
如何把“张三”、“李四”、“王小二”、“Thomas”、……、“唐”抽出来?
------解决方案--------------------
- Java code
String test = "张三\\李四\\王小二\\Thomas\\……\\唐"; Pattern p = Pattern.compile("(?<=^|\\\\)[^\\\\]+(?=\\\\|$)"); Matcher m = p.matcher(test); while(m.find()){ System.out.println(m.group()); }
------解决方案--------------------
- Java code
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); } }
------解决方案--------------------
------解决方案--------------------