Sources
S1 — MDN: Regular expressions (JavaScript Guide)
URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
- authority: official-docs
- supports: 第 1 课:正则表达式是什么、字面量模式匹配自身、字面量与特殊字符(元字符)之分,以及正则通过
test和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 theRegExpmethodstest()andexec()and with theStringmethodsmatch(),matchAll(),replace(), ...search(), andsplit()."
S2 — MDN: Character classes
URL: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Character_classes
- authority: official-docs
- supports: 第 2 课:方括号范围(
[a-d]等价于[abcd])、\d/\w/\s简写,以及点号匹配除行终止符外的任意字符(除非设置 s/dotAll 标志)。 - 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: 第 3、6 课:
*、+、?、{n}、{n,m}的含义,以及量词默认贪婪、尾随?使其变为非贪婪(懒惰)。 - 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: 第 4 课:
^匹配输入开头、$匹配结尾、\b匹配词边界,且匹配到的词边界长度为零(它是位置,不是字符)。 - 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
- authority: official-docs
- supports: 第 5 课:捕获组
(x)匹配并记住其文本、各组按左圆括号顺序出现在结果数组中,以及(?:x)只分组不捕获。 - key-fact: "Matches
xand 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: 第 5 课:
|分隔备选项、在正则表达式中优先级最低,以及要在更大的模式里限定其作用范围必须分组。 - 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: 第 1、5 课:不带 g 标志时,
match把第一个匹配作为数组返回,索引 0 是整个匹配,后续索引存放捕获组,并携带index和input属性。 - key-fact: "If the
gflag is not used, only the first complete match and its related capturing groups are returned. In this case,match()will return the same result asRegExp.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", plusindexandinputproperties.
S8 — regular-expressions.info: Character Classes
URL: https://www.regular-expressions.info/charclass.html
- authority: authoritative-guide
- supports: 第 2 课:字符类只匹配若干字符中的一个,且开头的插入符对字符类取反、匹配任何未列出的字符(与 MDN 字符类事实互为交叉验证)。
- 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: 第 4 课:
\b和^、$一样是锚点,在称为词边界的位置上匹配,且产生零长度匹配(与 MDN 零宽结论互为交叉验证)。 - 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: 第 6 课:量词是贪婪的(把前面的 token 重复尽可能多次),加
?后变懒惰(重复尽可能少的次数)(与 MDN 贪婪/懒惰事实互为交叉验证)。 - 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."