/regex/.test(string)
Alternation or OR operator: |
/yes|no|maybe/
"Hello, World!".match(/Hello/);
.
[^abc]
The longest possible part of a string that fits the regex pattern and returns it as a match
The smallest possible part of the string that satisfies the regex pattern
Greedy
/t[a-z]*?i/
[A-Za-z0-9_]
\w etc
With quantity specifiers:
let multipleA = /a{3,5}h/;
let multipleA = /ha{3,}h/;
let multipleHA = /ha{3}h/;
A pattern that tell JavaScript to look-ahead in your string to check for patterns further along
A positive lookahead will look to make sure the element in the search pattern is there, but won't actually match it.
let quit = "qu";
let quRegex= /q(?=u)/;
quit.match(quRegex); // Returns ["q"]
A negative lookahead will look to make sure the element in the search pattern is not there.
let noquit = "qt";
let qRegex = /q(?!u)/;
noquit.match(qRegex); // Returns ["q"]
let password = "abc123";
let checkPass = /(?=\w{3,6})(?=\D*\d)/;
checkPass.test(password); // Returns true
With capture groups:
let repeatStr = "regex regex";
let repeatRegex = /(\w+)\s\1/;
repeatRegex.test(repeatStr); // Returns true
repeatStr.match(repeatRegex); // Returns ["regex regex", "regex"]
"Code Camp".replace(/(\w+)\s(\w+)/, '$2 $1');