A regular expression to match a string containing two specific words (no matter the order, case sensitive).
/^(?=.*\bREGEX\b)(?=.*\bPATTERN\b).*$/
Matches:
- I Like REGEX and PATTERN.
- I Like PATTERN and REGEX.
- I Like PATTERN.REGEX.COM.
Non-matches:
- I Like PATTERNREGEX.COM.
- I Like Regex and Pattern.
- I Like Pattern and Regex.
See Also:
- Regex To Match A line That Doesn’t Contain A Specific Word
- Regex To Match Anything But One Or More Words
- Regex To Match One Of Two Or More Words In A String
- Regular Expression To Match Duplicate Words