Given two strings where first string may contain wild card characters and second string is a normal string. Write a function that returns true if the two strings match. The following are allowed wild card characters in first string.
* --> Matches with 0 or more instances of any character or set of characters. ? --> Matches with any one character.
For example, “g*ks” matches with “geeks” match. And string “ge?ks*” matches with “geeksforgeeks” (note ‘*’ at the end of first string). But “g*k” doesn’t match with “gee” as character ‘k’ is not present in second string.
Yes Yes No No Yes No Yes Yes
1) In the above solution, all non-wild characters of first string must be there is second string and all characters of second string must match with either a normal character or wildcard character of first string. Extend the above solution to work like other pattern searching solutions where the first string is pattern and second string is text and we should print all occurrences of first string in second.
2) Write a pattern searching function where the meaning of ‘?’ is same, but ‘*’ means 0 or more occurrences of the character just before ‘*’. For example, if first string is ‘a*b’, then it matches with ‘aaab’, but doesn’t match with ‘abb’.
This article is compiled by Vishal Chaudhary and reviewed by GeeksforGeeks team. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- WildCard pattern matching having three symbols ( * , + , ? )
- Dynamic Programming | Wildcard Pattern Matching | Linear Time and Constant Space
- Wildcard Pattern Matching
- Count the Number of matching characters in a pair of strings
- Find if an array contains a string with one mismatch
- Smallest window that contains all characters of string itself
- Python program to check if a string contains all unique characters
- Minimum Cost of deletions such that string does not contains same consecutive characters
- Check if a String contains any index with more than K active characters
- Check if a string contains uppercase, lowercase, special characters and numeric values
- String matching with * (that matches with any) in any of the two strings
- Applications of String Matching Algorithms
- Convert a number of length N such that it contains any one digit at least 'K' times
- Maximize count of non overlapping substrings which contains all occurrences of its characters
- Print all words matching a pattern in CamelCase Notation Dictonary
- Longest Common Prefix using Word by Word Matching
- Longest Common Prefix using Character by Character Matching
- Longest Common Prefix Matching | Set-6
- CamelCase Pattern Matching
- Prefix matching in Python using pytrie module