import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        System.out.print("Enter main string: ");
        String str = sc.nextLine();
        
        System.out.print("Enter pattern: ");
        String pattern = sc.nextLine();
        
        if (match(str, pattern)) {
            System.out.println("The given pattern is matching.");
        } else {
            System.out.println("The given pattern is not matching.");
        }
    }
    
    public static boolean match(String str, String pattern) {
        int i = 0, j = 0;
        int starIndex = -1, match = 0;
        
        while (i < str.length()) {
            if (j < pattern.length() && 
               (pattern.charAt(j) == str.charAt(i) || pattern.charAt(j) == '?')) {
                i++;
                j++;
            } 
            else if (j < pattern.length() && pattern.charAt(j) == '*') {
                starIndex = j;
                match = i;
                j++;
            } 
            else if (starIndex != -1) {
                j = starIndex + 1;
                match++;
                i = match;
            } 
            else {
                return false;
            }
        }
        
        while (j < pattern.length() && pattern.charAt(j) == '*') {
            j++;
        }
        
        return j == pattern.length();
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: