Python Wildcard Search a String or Array

Posted on August 26, 2019 at 12:14 pm

In Python you can use fnmatch to enable wildcard search:

import fnmatch

Wildcard search and array of strings:

lst = ['string1', 'testing', 'football']
 
if fnmatch.filter(lst, 'th?s'):
    print('Matched')

Wildcard search a string:

if fnmatch.fnmatch('readme.txt', '*.txt'):
    print('Matched')

Receive updates via email

Other Posts

Updated Posts