As the title says , I need to find two specific words in a sentence. But they can be in any order and any casing. How do I go about doing this using regex?
For example, I need to extract the words test
and long
from the following sentence whether the word test
comes first or long
comes.
This is a very long sentence used as a test
UPDATE: What I did not mention in the first part is that it needs to be case insensitive as well.
However, to recognize multiple words in any order using regex, I'd suggest the use of quantifier in regex: (\b(james|jack)\b. *){2,} . Unlike lookaround or mode modifier, this works in most regex flavours.
Multiline option, or the m inline option, enables the regular expression engine to handle an input string that consists of multiple lines. It changes the interpretation of the ^ and $ language elements so that they match the beginning and end of a line, instead of the beginning and end of the input string.
i) makes the regex case insensitive. (? s) for "single line mode" makes the dot match all characters, including line breaks.
You can use
(?=.*test)(?=.*long)
Source: MySQL SELECT LIKE or REGEXP to match multiple words in one record
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With