test()'s regular expression capability to reduce the size of the formula and add case-insensitivity.
test()returns true if the first string argument contains the substring specified in the second argument.
Match “jpg”, “jpeg”, “gif”, or “png” - regardless of character case.
()form what’s called a capture group.
|act as Boolean OR operators
essentially say, “Match any single character that is included here”.
test()would only return true if the first argument’s string contains “jpg”.
|for that, and they only work inside of a capture group created with parentheses
test()function would return true if the first argument contains any of the following:
test()to return true.
?character after another character (or character class), we can tell the regular expression engine (or “regex engine”) that character is optional. In other words, we’ll get a match if it shows up zero or one times.
jpeg, with case-sensitivity:
?to the original regular expression:
[Ee]?included, we’ll now match any version of “jpg” or “jpeg” regardless of any character’s case.
test()easy to understand.