HWOJ字符串通配符

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
    public static void main(String[] args) {  
        Scanner sc = new Scanner(System.in);
        String str1 = sc.next();
        String str2 = sc.next();
        if(match(str1,str2)){
            System.out.println("true");
        }else{
            System.out.println("false");
        }
    }

    private static boolean match(String s1, String s2) {
        // TODO Auto-generated method stub
        String re = s1.toUpperCase().replaceAll("\\*", "\\\\w*");//   \w单词字符:[a-zA-Z_0-9]
        String regex = re.replaceAll("\\?", "\\\\w");
        String str = s2.toUpperCase();
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(s2.toUpperCase());
        return m.matches();
    }  
}

你可能感兴趣的:(HWOJ字符串通配符)