删除公共字符(正则表达式)

题目描述

输入两个字符串,从第一字符串中删除第二个字符串中所有的字符。例如,输入”They are students.”和”aeiou”,则删除之后的第一个字符串变成”Thy r stdnts.”

输入描述:

每个测试输入包含2个字符串

输出描述:

输出删除后的字符串
示例1

输入

They are students. aeiou

输出

Thy r stdnts.

 1 /**
 2  * 
 3  * 删除公共字符
 4  *         1、根据正则表达式 分割 字符串
 5         2、对字符串进行拼接
 6  * @author Dell
 7  *
 8  */
 9 import java.util.Scanner;
10 public class Main {
11 public static void main(String[] args) {
12         Scanner sc =new Scanner(System.in);
13         String str1 = sc.nextLine();
14         String str2 = sc.nextLine();
15         String matching = "["+str2+"]"; // 正则表达式 
16         String []strs = str1.split(matching); //根据正则表达式 分割 字符串
17         String res = "";
18         for (int i = 0; i < strs.length; i++) { //对字符串进行拼接
19             res+=strs[i];
20         }
21         System.out.println(res);
22     }
23 }
原文地址:https://www.cnblogs.com/the-wang/p/8981319.html