Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/labs/regex0.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ <h2>Background</h2>
<li>Another rule is that square brackets surround a rule that specifies any of a number of characters. If the square brackets surround just alphanumerics, then the pattern matches any of them. So <tt>[brt]</tt> matches a single “<tt>b</tt>”, “<tt>r</tt>”, or “<tt>t</tt>”.
Inside the brackets you can include
ranges of symbols separated by dash ("-"), so
<tt>[A-D]</tt> will match one character, which can be one A, one B, one C,
or one D.
You can do this more than once.
<tt>[A-D]</tt> will match one character in that range,
which can be one A, one B, one C, or one D.
You can provide more than one range inside brackets.
For example,
the term <tt>[A-Za-z]</tt> will match one character, which can be
an uppercase Latin letter or a lowercase Latin letter.
(This text assumes you're not using a long-obsolete character system
like EBCDIC.)
(For purposes of our labs we're
assuming you're not using a long-obsolete character system like EBCDIC.)
<li>If you follow a pattern with “<tt>&#42;</tt>”, that means
“<i>0 or more times</i>”.
In almost all regex implementations (except POSIX BRE),
Expand Down
18 changes: 13 additions & 5 deletions docs/labs/regex0.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ info =
[ "x" ],
],
},
{
present: String.raw`\[(cat|act)\]`,
text: "The pattern '[cat]' or '[act]' matches one latter, a 'c', an 'a', or 't'. That is not what you want.",
examples: [
[ "[cat]" ],
[ "[act]" ],
],
},
{
absent: "cat",
text: "The pattern \"cat\" is needed to search for \"cat\".",
Expand All @@ -43,24 +51,24 @@ info =
index: 1,
text: "You need to mention A.",
examples: [
[ "cat", "B" ],
[ null, "B" ],
],
},
{
absent: String.raw`A(\+|A\*)`,
index: 1,
text: "Use \"A+\" to indicate \"one or more A\". You could also write \"AA*\".",
examples: [
[ "cat", "A" ],
[ "cat", "AA" ],
[ null, "A" ],
[ null, "AA" ],
],
},
{
absent: "B",
index: 1,
text: "You need to mention B.",
examples: [
[ "cat", "A+" ],
[ null, "A+" ],
],
},
{
Expand All @@ -69,7 +77,7 @@ info =
index: 1,
text: "Use \"B+\" to indicate \"one or more B\". You could also write \"BB*\".",
examples: [
[ "cat", "A+B" ],
[ null, "A+B" ],
],
},
],
Expand Down
79 changes: 51 additions & 28 deletions docs/labs/regex1.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,161 +5,184 @@ info =
present: "/",
text: "In JavaScript a constant regular expression is surrounded by forward slashes like /PATTERN/. However, for this exercise we only want the text inside the slashes (the pattern itself).",
examples: [
[ "/" ]
[ "/" ],
],
},
{
present: "[\"'`]",
text: "In this exercise we only want the regular expression pattern itself. There is no need to use any kind of quote mark.",
examples: [
[ "'" ]
[ "'" ],
],
},
{
absent: String.raw`^\^`,
text: "For input validation, start with '^' to indicate a full match.",
examples: [
[ "(Y|N)" ]
[ "(Y|N)" ],
],
},
{
present: String.raw`\\[Zz]`,
text: "The ECMAScript (JavaScript) specification does not support \\Z or \\z.",
examples: [
[ "^Y|N\\z" ]
[ "^Y|N\\z" ],
],
},
{
absent: String.raw`\$$`,
text: "For input validation, end with '$' to indicate a full match.",
examples: [
[ "^(Y|N)" ]
[ "^(Y|N)" ],
],
},
{
absent: String.raw`[\|\[]`,
text: "Consider using [YN], to match either a Y or an N.",
examples: [
[ "^$" ]
[ "^$" ],
],
},
{
present: String.raw`\|`,
absent: String.raw`\(`,
text: "If you use \"|\" you must parentheses or the precedence will be wrong. For example, \"^A|B$\" accepts anything beginning with A, and it also accepts anything ending with B. That is not what you want.",
examples: [
[ "^Y|N$" ]
[ "^Y|N$" ],
],
},
{
present: " ",
text: "Spaces normally match spaces in a regex. Do not use them in this case, because a space is not one of the allowed characters.",
examples: [
[ "^[YN] $" ]
[ "^[YN] $" ],
],
},
{
absent: String.raw`^\^`,
index: 1,
text: "For input validation, start with '^' to indicate a full match.",
examples: [
[ "^[YN]$", "" ]
[ null, "" ],
],
},
{
absent: String.raw`\$$`,
index: 1,
text: "For input validation, end with '$' to indicate a full match.",
examples: [
[ "^[YN]$", "^" ]
[ null, "^" ],
],
},
{
absent: String.raw`\[A-Z\]`,
index: 1,
text: "You can use [A-Z] to match one uppercase Latin letter (A through Z).",
examples: [
[ "^[YN]$", "^$" ]
[ null, "^$" ],
],
},
{
present: String.raw`\^\[A-Z\]\*`,
index: 1,
text: "A \"*\" matches one or more, not one or more."
text: "A \"*\" matches one or more, not one or more.",
examples: [
[ null, "^[A-Z]*$" ],
],
},
{
present: String.raw`\(`,
index: 1,
text: "You do not need parentheses to solve this problem."
text: "You do not need parentheses to solve this problem.",
examples: [
[ null, "^([A-Z])+$" ],
],
},
{
absent: String.raw`(\[A-Z\]\+|
\[A-Z\]\[A-Z\]\*)`,
absent: String.raw`\[A-Z\](\+|\[A-Z\]\*)`,
index: 1,
text: "You can use [A-Z]+ to match one or more uppercase Latin letters.",
examples: [
[ "^[YN]$", "^[A-Z]$" ]
[ null, "^[A-Z]$" ],
],
},
{
present: "True",
index: 2,
text: "Regular expressions are case-sensitive by default; use \"true\"."
text: "Regular expressions are case-sensitive by default; use \"true\"",
examples: [
[ null, null, "True" ],
],
},
{
present: "False",
index: 2,
text: "Regular expressions are case-sensitive by default; use \"false\"."
text: "Regular expressions are case-sensitive by default; use \"false\".",
examples: [
[ null, null, "False" ],
],
},
{
absent: String.raw`\|`,
index: 2,
text: "Use \"|\" to express alternatives."
text: "Use \"|\" to express alternatives.",
},
{
present: String.raw`^\^true\|false\$$`,
index: 2,
text: "No. This would match anything beginning with the term true, or anything ending with the term false. Use parenthesis."
text: "No. This would match anything beginning with the term true, or anything ending with the term false. Use parenthesis.",
},
{
present: String.raw`^\^false\|true\$$`,
index: 2,
text: "No. This would match anything beginning with the term false, or anything ending with the term true. Use parenthesis."
text: "No. This would match anything beginning with the term false, or anything ending with the term true. Use parenthesis.",
},
{
absent: String.raw`\(`,
index: 2,
text: "Use parentheses."
text: "Use parentheses.",
},
{
present: String.raw`\$`,
index: 3,
text: "This is Python, not ECMAScript (JavaScript). Use \\Z at the end, not $."
text: "This is Python, not ECMAScript (JavaScript). Use \\Z at the end, not $.",
examples: [
[ null, null, null, "^[A-Z]+$"],
],
},
{
present: String.raw`\\z`,
index: 3,
text: "This is Python. Use \\Z at the end, not \\z."
text: "This is Python. Use \\Z at the end, not \\z.",
examples: [
[ null, null, null, "^[A-Z]+\\z"],
],
},
{
absent: String.raw`^\\A`,
index: 4,
text: "This is Ruby. Use \\A at the beginning."
text: "This is Ruby. Use \\A at the beginning.",
examples: [
[ null, null, null, null, "^[A-Z]+$"],
],
},
{
absent: String.raw`\\z$`,
index: 4,
text: "This is Ruby. Use \\z at the end."
text: "This is Ruby. Use \\z at the end.",
examples: [
[ null, null, null, null, "\\A[A-Z]+$"],
],
},
{
absent: String.raw`\[A-Z\]`,
index: 4,
text: "Use [A-Z] to match one uppercase Latin letter."
text: "Use [A-Z] to match one uppercase Latin letter.",
},
{
present: String.raw`\[A-Z\](\*|\+)`,
index: 4,
text: "In this case we are only matching one letter, not many of them. Do not use \"*\" or \"+\" after [A-Z]."
text: "In this case we are only matching one letter, not many of them. Do not use \"*\" or \"+\" after [A-Z].",
},
],
expected: [
Expand Down