Skip to content

Commit 989fe04

Browse files
Regex1 no yaml (#736)
* Lab regex1: No YAML Signed-off-by: David A. Wheeler <[email protected]> * Lab regex1.html: Remove YAML Signed-off-by: David A. Wheeler <[email protected]> --------- Signed-off-by: David A. Wheeler <[email protected]>
1 parent 83524f6 commit 989fe04

File tree

2 files changed

+172
-162
lines changed

2 files changed

+172
-162
lines changed

docs/labs/regex1.html

Lines changed: 1 addition & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<link rel="stylesheet" href="checker.css">
88
<script src="js-yaml.min.js"></script>
99
<script src="checker.js"></script>
10+
<script src="regex1.js"></script>
1011
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
1112

1213
<!-- See create_labs.md for how to create your own lab! -->
@@ -85,168 +86,6 @@
8586
\\z
8687
</script>
8788

88-
<script id="info" type="application/yaml">
89-
---
90-
hints:
91-
- present: |-
92-
/
93-
text: In JavaScript a constant regular expression is surrounded by
94-
forward slashes like /PATTERN/. However, for this exercise we only
95-
want the text inside the slashes (the pattern itself).
96-
examples:
97-
- - "/"
98-
- present: |-
99-
["'`]
100-
text: In this exercise we only want the regular expression pattern itself.
101-
There is no need to use any kind of quote mark.
102-
examples:
103-
- - "'"
104-
- absent: |-
105-
^\^
106-
text: For input validation, start with '^' to indicate a full match.
107-
examples:
108-
- - "(Y|N)"
109-
- present: |-
110-
\\[Zz]
111-
text: The ECMAScript (JavaScript) specification does not support \Z or \z.
112-
examples:
113-
- - "^Y|N\\z"
114-
- absent: |-
115-
\$$
116-
text: For input validation, end with '$' to indicate a full match.
117-
examples:
118-
- - "^(Y|N)"
119-
- absent: |-
120-
[\|\[]
121-
text: Consider using [YN], to match either a Y or an N.
122-
examples:
123-
- - "^$"
124-
- present: |-
125-
\|
126-
absent: |-
127-
\(
128-
text: If you use "|" you must parentheses or the precedence will be wrong.
129-
For example, "^A|B$" accepts anything beginning with A, and it also
130-
accepts anything ending with B. That is not what you want.
131-
examples:
132-
- - "^Y|N$"
133-
- present: " "
134-
text: Spaces normally match spaces in a regex. Do not use them in this case,
135-
because a space is not one of the allowed characters.
136-
examples:
137-
- - "^[YN] $"
138-
- absent: |-
139-
^\^
140-
index: 1
141-
text: For input validation, start with '^' to indicate a full match.
142-
examples:
143-
-
144-
- "^[YN]$"
145-
- ""
146-
- absent: |-
147-
\$$
148-
index: 1
149-
text: For input validation, end with '$' to indicate a full match.
150-
examples:
151-
-
152-
- "^[YN]$"
153-
- "^"
154-
- absent: |-
155-
\[A-Z\]
156-
index: 1
157-
text: You can use [A-Z] to match one uppercase Latin letter (A through Z).
158-
examples:
159-
-
160-
- "^[YN]$"
161-
- "^$"
162-
- present: |-
163-
\^\[A-Z\]\*
164-
index: 1
165-
text: A "*" matches one or more, not one or more.
166-
- present: |-
167-
\(
168-
index: 1
169-
text: You do not need parentheses to solve this problem.
170-
- absent: |-
171-
(\[A-Z\]\+|
172-
\[A-Z\]\[A-Z\]\*)
173-
index: 1
174-
text: You can use [A-Z]+ to match one or more uppercase Latin letters.
175-
examples:
176-
-
177-
- "^[YN]$"
178-
- "^[A-Z]$"
179-
- present: "True"
180-
index: 2
181-
text: Regular expressions are case-sensitive by default; use "true".
182-
- present: "False"
183-
index: 2
184-
text: Regular expressions are case-sensitive by default; use "false".
185-
- absent: |-
186-
\|
187-
index: 2
188-
text: Use "|" to express alternatives.
189-
- present: |-
190-
^\^true\|false\$$
191-
index: 2
192-
text: No. This would match anything beginning with the term true,
193-
or anything ending with the term false. Use parenthesis.
194-
- present: |-
195-
^\^false\|true\$$
196-
index: 2
197-
text: No. This would match anything beginning with the term false,
198-
or anything ending with the term true. Use parenthesis.
199-
- absent: |-
200-
\(
201-
index: 2
202-
text: Use parentheses.
203-
- present: |-
204-
\$
205-
index: 3
206-
text: This is Python, not ECMAScript (JavaScript). Use \Z at the end, not $.
207-
- present: |-
208-
\\z
209-
index: 3
210-
text: This is Python. Use \Z at the end, not \z.
211-
- absent: |-
212-
^\\A
213-
index: 4
214-
text: This is Ruby. Use \A at the beginning.
215-
- absent: |-
216-
\\z$
217-
index: 4
218-
text: This is Ruby. Use \z at the beginning.
219-
- absent: |-
220-
\[A-Z\]
221-
index: 4
222-
text: Use [A-Z] to match one uppercase Latin letter.
223-
- present: |-
224-
\[A-Z\](\*|\+)
225-
index: 4
226-
text: In this case we are only matching one letter, not many of them.
227-
Do not use "*" or "+" after [A-Z].
228-
# successes:
229-
# - - " query ( 'id' ) . isInt ( {min: 1 , max: 9999 } ) ,"
230-
# - - " query ( `id` ) . isInt ( {min: 1 , max: 9_999 } ) , "
231-
# - - 'query ( "id" ) . isInt ( {min: 1 , max: 9_999 } ) ,'
232-
# failures:
233-
# - - " query,"
234-
# - - 'query(''id'').isint({min: 1, max: 9999})'
235-
# - - 'query(''id'').isInt({min: 1, max: 9999})'
236-
#
237-
# Remove all whitespace, so we can make our patterns easier to read
238-
#
239-
preprocessing:
240-
-
241-
- |-
242-
\s*
243-
- ""
244-
# -
245-
# - |-
246-
# (\\s\*)?\s+(\\s\*)?
247-
# - "\\s*"
248-
# debug: true
249-
</script>
25089
<!--
25190
25291
-->

docs/labs/regex1.js

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
info =
2+
{
3+
hints: [
4+
{
5+
present: "/",
6+
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).",
7+
"examples": [
8+
[ "/" ]
9+
]
10+
},
11+
{
12+
present: "[\"'`]",
13+
text: "In this exercise we only want the regular expression pattern itself. There is no need to use any kind of quote mark.",
14+
"examples": [
15+
[ "'" ]
16+
]
17+
},
18+
{
19+
absent: String.raw`^\^`,
20+
text: "For input validation, start with '^' to indicate a full match.",
21+
"examples": [
22+
[ "(Y|N)" ]
23+
]
24+
},
25+
{
26+
present: String.raw`\\[Zz]`,
27+
text: "The ECMAScript (JavaScript) specification does not support \\Z or \\z.",
28+
"examples": [
29+
[ "^Y|N\\z" ]
30+
]
31+
},
32+
{
33+
absent: String.raw`\$$`,
34+
text: "For input validation, end with '$' to indicate a full match.",
35+
"examples": [
36+
[ "^(Y|N)" ]
37+
]
38+
},
39+
{
40+
absent: String.raw`[\|\[]`,
41+
text: "Consider using [YN], to match either a Y or an N.",
42+
"examples": [
43+
[ "^$" ]
44+
]
45+
},
46+
{
47+
present: String.raw`\|`,
48+
absent: String.raw`\(`,
49+
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.",
50+
"examples": [
51+
[ "^Y|N$" ]
52+
]
53+
},
54+
{
55+
present: " ",
56+
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.",
57+
"examples": [
58+
[ "^[YN] $" ]
59+
]
60+
},
61+
{
62+
absent: String.raw`^\^`,
63+
"index": 1,
64+
text: "For input validation, start with '^' to indicate a full match.",
65+
"examples": [
66+
[ "^[YN]$", "" ]
67+
]
68+
},
69+
{
70+
absent: String.raw`\$$`,
71+
"index": 1,
72+
text: "For input validation, end with '$' to indicate a full match.",
73+
"examples": [
74+
[ "^[YN]$", "^" ]
75+
]
76+
},
77+
{
78+
absent: String.raw`\[A-Z\]`,
79+
"index": 1,
80+
text: "You can use [A-Z] to match one uppercase Latin letter (A through Z).",
81+
"examples": [
82+
[ "^[YN]$", "^$" ]
83+
]
84+
},
85+
{
86+
present: String.raw`\^\[A-Z\]\*`,
87+
"index": 1,
88+
text: "A \"*\" matches one or more, not one or more."
89+
},
90+
{
91+
present: String.raw`\(`,
92+
"index": 1,
93+
text: "You do not need parentheses to solve this problem."
94+
},
95+
{
96+
absent: String.raw`(\[A-Z\]\+|
97+
\[A-Z\]\[A-Z\]\*)`,
98+
"index": 1,
99+
text: "You can use [A-Z]+ to match one or more uppercase Latin letters.",
100+
"examples": [
101+
[ "^[YN]$", "^[A-Z]$" ]
102+
]
103+
},
104+
{
105+
present: "True",
106+
"index": 2,
107+
text: "Regular expressions are case-sensitive by default; use \"true\"."
108+
},
109+
{
110+
present: "False",
111+
"index": 2,
112+
text: "Regular expressions are case-sensitive by default; use \"false\"."
113+
},
114+
{
115+
absent: String.raw`\|`,
116+
"index": 2,
117+
text: "Use \"|\" to express alternatives."
118+
},
119+
{
120+
present: String.raw`^\^true\|false\$$`,
121+
"index": 2,
122+
text: "No. This would match anything beginning with the term true, or anything ending with the term false. Use parenthesis."
123+
},
124+
{
125+
present: String.raw`^\^false\|true\$$`,
126+
"index": 2,
127+
text: "No. This would match anything beginning with the term false, or anything ending with the term true. Use parenthesis."
128+
},
129+
{
130+
absent: String.raw`\(`,
131+
"index": 2,
132+
text: "Use parentheses."
133+
},
134+
{
135+
present: String.raw`\$`,
136+
"index": 3,
137+
text: "This is Python, not ECMAScript (JavaScript). Use \\Z at the end, not $."
138+
},
139+
{
140+
present: String.raw`\\z`,
141+
"index": 3,
142+
text: "This is Python. Use \\Z at the end, not \\z."
143+
},
144+
{
145+
absent: String.raw`^\\A`,
146+
"index": 4,
147+
text: "This is Ruby. Use \\A at the beginning."
148+
},
149+
{
150+
absent: String.raw`\\z$`,
151+
"index": 4,
152+
text: "This is Ruby. Use \\z at the end."
153+
},
154+
{
155+
absent: String.raw`\[A-Z\]`,
156+
"index": 4,
157+
text: "Use [A-Z] to match one uppercase Latin letter."
158+
},
159+
{
160+
present: String.raw`\[A-Z\](\*|\+)`,
161+
"index": 4,
162+
text: "In this case we are only matching one letter, not many of them. Do not use \"*\" or \"+\" after [A-Z]."
163+
}
164+
],
165+
preprocessing: [
166+
[
167+
"\\s*",
168+
""
169+
]
170+
]
171+
}

0 commit comments

Comments
 (0)