Algorithm to find closest document containing a set of strings, or variations of them I have one dataset (A) containing several fields (strings) per sample. One of these fields is a name, and the others are all alphanumeric identifiers.
I have another dataset (B) which contains highly unstructured strings of text which can include some of these names or unique identifiers. These strings have a large number of variations in the way they are formatted, so creating rules and/or regular expressions to try to extract the fields is probably not achievable.
Two big issues are that:

*

*the names in B may be slight variations of the names in A

*the unique identifiers from A may be truncated or concatenated with other characters in B or may have spaces within them

I would like to create an algorithm to find the closest match(es) from B for each of the samples in A, based on how many of the fields in A's samples are contained in each string in B. If a sample in B contains all of the fields of a sample of A, then it should be an extremely close/perfect match.
There is at most a 1-1 match between samples in the two datasets, but there may be many samples that have similar data, hence why I want to find the closest/best match, or even a list of the best matches to choose from.
Unfortunately, my actual data is banking transactions so I cannot share it. I have tried to simulate an explainable example of data below. Each row in dataset B below is an example of a match for the corresponding row in dataset A. I have highlighted the parts which match.
Dataset A:
name               id1        id2       id3
---------------------------------------------------
John Smith         AJM4268    455997407 AB012423
Jane Doe           8939BQDFWS 455956471 AB019472
Frank Andrew Jones 849281     456090494 XE039130

Dataset B:
SB-TRANSFER SBN124092095 SB REF.-:45599740730086733 MR JOHN P SMITH Value DATE, 01/01/22 - AB012423 B/O SOME ORG LTD
                                  ^^^^^^^^^         ^^^^^^^^^^^^^^^                        ^^^^^^^^
BANKNET BNKE107589639204132 AB0194 FROM - 10582390183 APR 22;8939BQDFWS BNK REF.-455956471
                            ^^^^^^                           ^^^^^^^^^^          ^^^^^^^^^
EST LOCALTRANSFER ESTX3843940734 JONES MR F A TRANSFER; EST REF .-849281;MSG-45609 0494 VALUE DATE 03-03-22 - XE039130
                                 ^^^^^^^^^^^^                     ^^^^^^     ^^^^^^^^^^                       ^^^^^^^^

My initial intuition would be that using embeddings somehow would work well. However, I am not aware of a way to do this since the values in dataset A would be substrings of the values in dataset B.

Word embeddings are better for capturing information realated to the concept and meaning of each term considering the context in each sentence that a word/term might be present.
If you just want to compare string and find the most similar one(s), it might more useful to consider a metric like levenshtein distance in order to be able to compare any available pair of strings.
