loading...

re: Daily Challenge #243 - Redacted! VIEW POST

FULL DISCUSSION
 

Python 3, using regex'es:

# Solution
import re
match = lambda doc1, doc2: re.match(re.sub('X+', '.*?', doc1), doc2) is not None

# Test cases
cases = [
    ("TOP SECRET:\nThe missile launch code for Sunday XXXXXXXXXX is:\nXXXXXXXXXXXXXXXXX","TOP SECRET:\nThe missile launch code for Sunday 5th August is:\n7-ZERO-8X-ALPHA-1"),
    ("The name of the mole is Professor XXXXX", "The name of the mole is Professor Dinglemouse"),
    ("XXXXXXXX XXXXXXX XXXXXXXXXXXXXXXXXXX\nXXXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXXXXXXXX XXXXXXXXXXXXX XXXXX", "Area-51. Medical Report. 23/Oct/1969\nE.T. subject 4 was given an asprin after reporting sick for duty today")]

for case in cases:
    print(f"doc1: {re.sub('X+', '*', case[0])}\ndoc2: {case[1]}\nDoc's match: {match(*case)}")

Try it online!

code of conduct - report abuse