题解 | #字符串通配符#
字符串通配符
https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036
// mark一下
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
// 全部替换为小写字母
String s1 = in.nextLine().toLowerCase();
String s2 = in.nextLine().toLowerCase();
// 将2个以上的*合并为1个
s1 = s1.replaceAll("\\*{2,}", "\\*");
// 本题的?的含义替换为对应含义的正则表达式
s1 = s1.replaceAll("\\?", "[0-9a-z]{1}");
// 本题的*的含义替换为对应含义的正则表达式
s1 = s1.replaceAll("\\*", "[0-9a-z]{0,}");
System.out.println(s2.matches(s1));
}
}
}
