Regex To Match A String Containing Two Words

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: