I want to find if all of a list of substrings exist in a string, in the correct order (with or without spaces between them), it seems to be a good use for regex.
I think I need to build a regex filter of "a.*b.*c"
and use search to find that anywhere in my string.
Are there any other approaches I could consider or built in functions that might do this for me?
from re import search
def are_substrings_in_text(substrings,text):
return search("".join([s+".*" for s in substrings]),text) is not None
print(are_substrings_in_text(["a","b","c"],"abacus")) # >True
print(are_substrings_in_text(["a","c","b"],"abacus")) # >False
print(are_substrings_in_text(["a","c","z"],"abacus")) # >False