I just learned how to match a string with a wildcard from (very helpful) Python wildcard search in string
Now I'm trying to match two strings that both have wildcards.
string1 = "spotify.us.*.uk"
string2 = "spotify.*.co.uk"
These two strings should be a match. Using *
will be used as wildcard. My research online shows no solution. What I have so far (not working):
import re
string1 = "spotify.us.*.uk"
string2 = "spotify.*.co.uk"
r1 = string1.replace("*", ".*")
r2 = string2.replace("*", ".*")
regex1 = re.compile('.*'+r1)
regex2 = re.compile('.*'+r2)
matches = re.search(regex1, regex2)
I used the same concept to match a string
and a regex
which was a working. But it doesn't work in this case where both string have wildcards. Any help would be much appreciated.