I'm stuck in the following situation: I have a dictionary of words in a mongodb bank, where each word is stored in a document, which has additional information about it.
I need a regular expression that can find each document through the word, since some words in the database have a wildcard at the end (*). When this occurs, the wildcard word must be found if it is at the beginning of the search string. It is a kind of regular expression in the database, to simplify the word registration. Thus, it suffices that the document has only the necessary part of the word with the wildcard at the end so that it is returned when the search string "marries" with the word. It would be impracticable to register every possible word, and to be completely unnecessary, since many words have exactly the same additional information.
To make the situation clearer, here are some examples:
- If the word in the database is "asked", the document should be returned whenever the search string starts with "ask" (question, ask, ask, etc.)
- If the word in the database is "amig *", the document should be returned whenever the search string starts with "friend" (friend, friend, etc.)
- If the word in the database is "love," the document should be returned whenever the search string is exactly "love."
I need a single regular expression that will serve all of the above (wildcard at the end, no wildcard).
If possible, also show a solution for cases where the wildcard is also at the beginning of the word (* word *), in this case, a same regular expression for all situations (wildcard at the beginning, wildcard at the end, wildcard at the beginning and in the end, no wildcard).
I thank you in advance. It will help me a lot.