Sources

S1 — MDN: Regular expressions (JavaScript Guide)

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions

  • authority: official-docs
  • supports: Lesson 01 — what a regex is, that literal patterns match themselves, the split between literal and special characters (metacharacters), and that regexes are run with methods like test and match.
  • key-fact: "Regular expressions are patterns used to match character combinations in strings." "the pattern /abc/ matches character combinations in strings only when the exact sequence \"abc\" occurs (all characters together and in that order)." "When the search for a match requires something more than a direct match, such as finding one or more b's, or finding white space, you can include special characters in the pattern." "Regular expressions are used with the RegExp methods test() and exec() and with the String methods match(), matchAll(), replace(), ... search(), and split()."

S2 — MDN: Character classes

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Character_classes

  • authority: official-docs
  • supports: Lesson 02 — bracket ranges ([a-d] equals [abcd]), the \d / \w / \s shorthands, and that the dot matches any character except line terminators unless the s/dotAll flag is set.
  • key-fact: "For example, [abcd] is the same as [a-d]." "\d ... Matches any digit (Arabic numeral). Equivalent to [0-9]." "\w ... Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_]." "Wildcard: Matches any single character except line terminators: \n, \r, or . ... If the dotAll (s) flag is enabled, also matches line terminators."

S3 — MDN: Quantifiers

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Quantifiers

  • authority: official-docs
  • supports: Lessons 03 and 06 — the meaning of *, +, ?, {n}, {n,m}, and that quantifiers are greedy by default while a trailing ? makes them non-greedy (lazy).
  • key-fact: "Matches the preceding item 'x' 1 or more times. Equivalent to {1,}. For example, /a+/ matches the 'a' in 'candy' and all the 'a''s in 'caaaaaaandy'." "matches exactly 'n' occurrences of the preceding item 'x'." "By default quantifiers like * and + are 'greedy', meaning that they try to match as many times as possible. The ? character after the quantifier makes the quantifier 'non-greedy': meaning that it will stop as soon as it finds the minimum number of matches."

S4 — MDN: Assertions (anchors and boundaries)

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Assertions

  • authority: official-docs
  • supports: Lesson 04 — ^ matches the beginning of input, $ the end, \b a word boundary, and that a matched word boundary has zero length (it is a position, not a character).
  • key-fact: "Input boundary beginning assertion: Matches the beginning of input. If the multiline (m) flag is enabled, also matches immediately after a line break character." "Input boundary end assertion: Matches the end of input." "Word boundary assertion: Matches a word boundary. This is the position where a word character is not followed or preceded by another word-character... Note that a matched word boundary is not included in the match. In other words, the length of a matched word boundary is zero."

S5 — MDN: Groups and backreferences

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Groups_and_backreferences

  • authority: official-docs
  • supports: Lesson 05 — a capturing group (x) matches and remembers its text, groups appear in the result array in the order of their opening parentheses, and (?:x) groups without capturing.
  • key-fact: "Matches x and remembers the match. For example, /(foo)/ matches and remembers 'foo' in 'foo bar'." "In results, matches to capturing groups typically in an array whose members are in the same order as the left parentheses in the capturing group." (Non-capturing group) "Matches 'x' but does not remember the match. The matched substring cannot be recalled from the resulting array's elements."

S6 — MDN: Disjunction (the | operator)

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Disjunction

  • authority: official-docs
  • supports: Lesson 05 — | separates alternatives, has the lowest precedence in a regular expression, and must be grouped to limit its scope inside a larger pattern.
  • key-fact: "A disjunction specifies multiple alternatives. Any alternative matching the input causes the entire disjunction to be matched." "The | operator has the lowest precedence in a regular expression." "If you want to use a disjunction as a part of a bigger pattern, you must group it."

S7 — MDN: String.prototype.match()

URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match

  • authority: official-docs
  • supports: Lessons 01 and 05 — without the g flag, match returns the first match as an array whose index 0 is the whole match, whose later indices hold the captured groups, and which carries index and input properties.
  • key-fact: "If the g flag is not used, only the first complete match and its related capturing groups are returned. In this case, match() will return the same result as RegExp.prototype.exec() (an array with some extra properties)." The documented example array shows index 0 as "the whole match", index 1 as "the first capture group", plus index and input properties.

S8 — regular-expressions.info: Character Classes

URL: https://www.regular-expressions.info/charclass.html

  • authority: authoritative-guide
  • supports: Lesson 02 — a character class matches only one out of several characters, and a leading caret negates the class so it matches any character not listed (cross-check of the MDN character-class facts).
  • key-fact: "With a 'character class', also called 'character set', you can tell the regex engine to match only one out of several characters." "A caret after the opening square bracket negates the character class. It then matches any character that is not in the character class."

S9 — regular-expressions.info: Word Boundaries

URL: https://www.regular-expressions.info/wordboundaries.html

  • authority: authoritative-guide
  • supports: Lesson 04 — \b is an anchor like ^ and $ that matches at a position (a word boundary) and produces a zero-length match (cross-check of the MDN zero-width claim).
  • key-fact: "The metacharacter \b is an anchor like the caret and the dollar sign. It matches at a position that is called a 'word boundary'. This match is zero-length."

S10 — regular-expressions.info: Repetition (greedy and lazy)

URL: https://www.regular-expressions.info/repeat.html

  • authority: authoritative-guide
  • supports: Lesson 06 — quantifiers are greedy (repeat the preceding token as often as possible), and adding ? makes them lazy (repeat as few times as possible) (cross-check of the MDN greedy/lazy facts).
  • key-fact: "the plus is greedy. That is, the plus causes the regex engine to repeat the preceding token as often as possible." "This tells the regex engine to repeat the dot as few times as possible."