wildcard machting algorithm problem



  • Hi,

    ich moechte folgendes problem loesen, weiss aber nicht so recht wie ich '*' matchen soll... den wildcard string in tokens zerlegen?

    String matching where one string contains wildcard characters
    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.
    

    testfaelle:

    test("g*ks", "geeks"); // Yes
    test("ge?ks*", "geeksforgeeks"); // Yes
    test("g*k", "gee");  // No because 'k' is not in second
    test("*pqrs", "pqrst"); // No because 't' is not in first
    test("abc*bcd", "abcdhghgbcd"); // Yes
    test("abc*c?d", "abcd"); // No because second must have 2
    
    test("*c*d", "abcd"); // Yes
    test("*?c*d", "abcd"); // Yes
    

  • Mod


Anmelden zum Antworten