1
代码:
public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入点评的条数"); int line=sc.nextInt(); sc.nextLine(); String a[] = new String[line]; for(int i=0;i<line;i++){ a[i]=sc.nextLine(); } String s[]={"网店地址","销售电话","代购"}; regMatch(s,a); } public static void regMatch(String[] reg,String s[]){ StringBuffer sb=new StringBuffer(); for(int i=0;i<reg.length;i++){ for(int j=0;j<reg[i].length();j++){ sb.append("\s*"+reg[i].charAt(j)); } if(i==reg.length-1){ break; } sb.append("|"); } Pattern p=Pattern.compile(sb.toString()); Matcher m=null; for(String str:s){ m=p.matcher(str); while(m.find()){ System.out.print(m.group()+" "); } System.out.println(); } }