import re


def Amatch(tmpl, strn):
    """
    Test for AIPS match of string
    
    A "?" matches one of any character, "*" matches any string
    all blanks matches anything
    Returns True or False

    * tmpl     = Template string
    * strng    = String to search for occurance of tmpl
    """
    # All blank?
    if re.match("^ *$",tmpl):
        return True
    # Full test
    t   = re.escape(tmpl.strip())
    tt  = t.replace("\\?",".")
    ttt = tt.replace("\\*",".*")
    pat = "^"+ttt+"$"
    m = re.match(pat,strn.strip())
    return m!=None
    # end Amatch