题解 | #字符串通配符#
字符串通配符
https://www.nowcoder.com/practice/43072d50a6eb44d2a6c816a283b02036
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String a = ""; String b = ""; // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNext()) { // 注意 while 处理多个 case a = in.nextLine().toLowerCase(Locale.ROOT); b = in.nextLine().toLowerCase(Locale.ROOT); } //多个星号换成一个星号 a = a.replaceAll("\\*{2,}","\\*"); // //?换成一个0-9a-z正则 a = a.replace("?", "[0-9a-z]{1}"); //*换成n个0-9a-z正则 a = a.replace("*", "[0-9a-z]{0,}"); System.out.println(b.matches(a)); } }