"""

Anish Patel

W.G. Enloe High

01/21/2010

Contest #2

Intermediate -5  Division

Potter

"""

 

# Programmed in Python 2.6.6

 

import re

 

print 'Enter search data: '

data = [word.strip().upper() for word in raw_input('INPUT 1. ').split(',')]

 

print '\nEnter search queries: '

for i in range(1, 6):

    query = raw_input('INPUT {0}. '.format(i+1)).strip().upper()

    query = query.replace('?', '.')

    query = query.replace('*', '?')

    query = query.replace('?', '.*')

    query += '$'

 

    no_match = True

    print 'OUTPUT {0}. '.format(i),

    for word in data:

        if re.match(query, word):

            print '{0},'.format(word),

            no_match = False

    if no_match:

        print 'No Match',

    print '\n'

 

raw_input('\nPress enter to exit . . .')

 

# Sample Input (Senior)

"""

2BELLS, T4LLS, FALLS, DOL3LS, DUL7LS, DOLLIES, BELLY, BELLIES, TELLY, DELL

*LLS

[2-5]BELLS

*L?LS

*BELL*

*L[1-8]*

"""

 

# Sample Input (Intermediate)

"""

2BELLS, DOLLS, BELLY, BELLIES

*LLS

[2-5]BELLS

*L?LS

BELL*

*LL?

"""