Videos
regex - Regular Expressions: Is there an AND operator? - Stack Overflow
Explain Like I'm 5: Regular Expressions
What exactly is regex used for?
Regular Expressions, aka Regex, examples
I took a short look and jumped around a bit, and I think this is lacking enough explanation to help beginners, and also lacks enough depth to help experts. I'm not sure who would benefit from this.
For example:
.1. Using the Regex Test Method
var result = regex.test(string);
You show that running your sample code returns true. A beginner might want to know what it is doing -- in this case, testing if the literal string the is present in the search string, and returning true because it is there. I am not sure that this would be obvious to a total beginner. Also, you don't explain that the regular expression is enclosed in /, so maybe a beginner can misinterpret.
.4. Ignore Case While Matching
You don't explain that javascript regexes have flags or that they are placed at the back of the object, you just throw in the 'i' flag in there. I'm not sure that this would be sufficiently obvious to a total beginner.
.19. Match All Letters and Numbers
var regex = /\w/g;
\w also matches the underscore character _ in addition to letters and numbers. I think you'd want the old fashioned [a-zA-Z0-9] to match all letters and numbers without extra characters.
.26. Specify Upper and Lower Number of Matches
var regex = /Oh{3,6} no/;
This doesn't change the number of matches, the {} quantifier changes the number of letters allowed in a single match.
Overall, this tutorial seems a mix of how javascript handles regular expressions and regex syntax itself. Also, you are inconsistent with ending statements with a ;. The first 4 regexes aren't ended with a ;, the rest are.
Use a non-consuming regular expression.
The typical (i.e. Perl/Java) notation is:
(?=expr)
This means "match expr but after that continue matching at the original match-point."
You can do as many of these as you want, and this will be an "and." Example:
(?=match this expression)(?=match this too)(?=oh, and this)
You can even add capture groups inside the non-consuming expressions if you need to save some of the data therein.
You need to use lookahead as some of the other responders have said, but the lookahead has to account for other characters between its target word and the current match position. For example:
(?=.*word1)(?=.*word2)(?=.*word3)
The .* in the first lookahead lets it match however many characters it needs to before it gets to "word1". Then the match position is reset and the second lookahead seeks out "word2". Reset again, and the final part matches "word3"; since it's the last word you're checking for, it isn't necessary that it be in a lookahead, but it doesn't hurt.
In order to match a whole paragraph, you need to anchor the regex at both ends and add a final .* to consume the remaining characters. Using Perl-style notation, that would be:
/^(?=.*word1)(?=.*word2)(?=.*word3).*$/m
The 'm' modifier is for multline mode; it lets the ^ and $ match at paragraph boundaries ("line boundaries" in regex-speak). It's essential in this case that you not use the 's' modifier, which lets the dot metacharacter match newlines as well as all other characters.
Finally, you want to make sure you're matching whole words and not just fragments of longer words, so you need to add word boundaries:
/^(?=.*\bword1\b)(?=.*\bword2\b)(?=.*\bword3\b).*$/m