Python - search list with only a few characters entered
Question: I want to find the string that the user searches for. For example, if the user
enters FD-2** (he doesnt know what the * characters are), the search should
give FD-234 and FD-285. I have a piece of code:

    
    
    rendszam = input('Adja meg a rendszámot! ')
    matching = [s for s in rszamok if rendszam in s]
    print(matching)
    

How can I do that?


Answer: The easiest way is to use a regular expression:

    
    
    >>> import re
    >>> targets = 'FD-234 XY-456 FD-285 XY-890 FD-999'
    >>> search = 'FD-2**'
    >>> pattern = search.replace('*', '.')
    >>> re.findall(pattern, targets)
    ['FD-234', 'FD-285']
    

