Skip to content

Commit ebdf533

Browse files
regex.html: Add first draft
Signed-off-by: David A. Wheeler <[email protected]>
1 parent 15382e5 commit ebdf533

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed

docs/labs/regex1.html

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<link rel="stylesheet" href="/assets/css/style.css">
7+
<link rel="stylesheet" href="checker.css">
8+
<script src="js-yaml.min.js"></script>
9+
<script src="checker.js"></script>
10+
<link rel="license" href="https://creativecommons.org/licenses/by/4.0/">
11+
12+
<!-- See create_labs.md for how to create your own lab! -->
13+
14+
<!-- Sample expected answer -->
15+
<script id="expected0" type="plain/text">
16+
^[YN]$
17+
</script>
18+
19+
<!-- Full pattern of correct answer -->
20+
<script id="correct0" type="plain/text">
21+
\^(
22+
\[YN\]|
23+
\[NY\]|
24+
\(Y\|N\)|
25+
\(N\|Y\)
26+
)\$
27+
</script>
28+
29+
<!-- Sample expected answer -->
30+
<script id="expected1" type="plain/text">
31+
^(true|false)$
32+
</script>
33+
34+
<!-- Full pattern of correct answer -->
35+
<script id="correct1" type="plain/text">
36+
\^\((
37+
true\|false|
38+
false\|true
39+
)\)\$
40+
</script>
41+
42+
<script id="info" type="application/yaml">
43+
---
44+
hints:
45+
- absent: |-
46+
^\^
47+
text: For input validation, start with '^' to indicate a full match.
48+
examples:
49+
- - "(Y|N)"
50+
- absent: |-
51+
\$$
52+
text: For input validation, end with '$' to indicate a full match.
53+
examples:
54+
- - "^(Y|N)"
55+
- present: |-
56+
\|
57+
absent: |-
58+
\(
59+
text: If you use "|" you must parentheses or the precedence will be wrong.
60+
examples:
61+
- - "^Y|N$"
62+
# - - " query(),"
63+
# - present: query \( ["'`]id["'`] \) [^. ]
64+
# text: After query("id") use a period to invoke a verification method.
65+
# examples:
66+
# - - " query('id'),"
67+
# - present: "(isint|Isint|IsInt|ISINT)"
68+
# text: JavaScript is case-sensitive. Use isInt instead of the case you have.
69+
# examples:
70+
# - - " query('id').isint(),"
71+
# - - " query('id').IsInt(),"
72+
# - absent: isInt
73+
# text: Use isInt to determine if the parameter is an integer.
74+
# examples:
75+
# - - " query('id').,"
76+
# - present: ' query \( ["''`]id["''`] \).*\([^)]*$'
77+
# text: After query("id") you have an ( but there's no matching ).
78+
# examples:
79+
# - - " query('id').isInt(,"
80+
# - absent: isInt \(.*\)
81+
# text: isInt should be followed by (...).
82+
# examples:
83+
# - - " query('id').isInt,"
84+
# - present: "\\{[^}]*$"
85+
# text: You have started an object using { but there's no matching }.
86+
# examples:
87+
# - - " query('id').isInt({),"
88+
# - absent: isInt \( \{.*\} \)
89+
# text: Inside the parenthesis of isInt() you should have an object like {...}.
90+
# examples:
91+
# - - " query('id').isInt(),"
92+
# - absent: min
93+
# text: 'Use min: to specify a minimum value.'
94+
# examples:
95+
# - - " query('id').isInt({}),"
96+
# - absent: max
97+
# text: 'Use max: to specify a minimum value.'
98+
# examples:
99+
# - - " query('id').isInt({min: 1}),"
100+
# - present: max.*min
101+
# text: JavaScript allows hash entries to be in any order,
102+
# but this can be confusing to humans. Conventionally minimum values
103+
# are given before maximum values; please follow that convention.
104+
# examples:
105+
# - - " query('id').isInt({max: 9999, min: 1}),"
106+
# successes:
107+
# - - " query ( 'id' ) . isInt ( {min: 1 , max: 9999 } ) ,"
108+
# - - " query ( `id` ) . isInt ( {min: 1 , max: 9_999 } ) , "
109+
# - - 'query ( "id" ) . isInt ( {min: 1 , max: 9_999 } ) ,'
110+
# failures:
111+
# - - " query,"
112+
# - - 'query(''id'').isint({min: 1, max: 9999})'
113+
# - - 'query(''id'').isInt({min: 1, max: 9999})'
114+
#
115+
# Remove all whitespace, so we can make our patterns easier to read
116+
#
117+
preprocessing:
118+
-
119+
- |-
120+
\s*
121+
- ""
122+
# -
123+
# - |-
124+
# (\\s\*)?\s+(\\s\*)?
125+
# - "\\s*"
126+
# debug: true
127+
</script>
128+
<!--
129+
130+
-->
131+
132+
</head>
133+
<body>
134+
<!-- For GitHub Pages formatting: -->
135+
<div class="container-lg px-3 my-5 markdown-body">
136+
<h1>Lab Exercise regex1</h1>
137+
<p>
138+
This is a lab exercise on developing secure software.
139+
For more information, see the <a href="introduction.html">introduction to
140+
the labs</a>.
141+
142+
<p>
143+
<h2>Task</h2>
144+
<p>
145+
<b>Please create various regex patterns that meet the criteria below.</b>
146+
147+
<p>
148+
<h2>Background</h2>
149+
<p>
150+
151+
<p>
152+
<h2>Task Information</h2>
153+
<p>
154+
155+
<p>
156+
<h2>Interactive Lab (<span id="grade"></span>)</h2>
157+
158+
<h3>Part 1</h2>
159+
<p>
160+
Create a regular expression, for use in JavaScript,
161+
that only matches the letters "Y" or "N".
162+
<!--
163+
You can use this an example for new labs.
164+
For multi-line inputs, instead of <input id="attempt0" type="text" ...>, use
165+
<textarea id="attempt" rows="2" cols="70">...</textarea>
166+
-->
167+
<form id="lab1">
168+
<pre></code>
169+
<input id="attempt0" type="text" size="70" spellcheck="false" value="">
170+
</code></pre>
171+
<button type="button" class="hintButton">Hint</button>
172+
<button type="button" class="resetButton">Reset</button>
173+
<button type="button" class="giveUpButton">Give up</button>
174+
</form>
175+
176+
<h3>Part 2</h2>
177+
<p>
178+
Create a regular expression, for use in JavaScript,
179+
that only matches the words "true" or "false".
180+
<!--
181+
You can use this an example for new labs.
182+
For multi-line inputs, instead of <input id="attempt0" type="text" ...>, use
183+
<textarea id="attempt" rows="2" cols="70">...</textarea>
184+
-->
185+
<form id="lab2">
186+
<pre></code>
187+
<input id="attempt1" type="text" size="70" spellcheck="false" value="">
188+
</code></pre>
189+
<button type="button" class="hintButton">Hint</button>
190+
<button type="button" class="resetButton">Reset</button>
191+
<button type="button" class="giveUpButton">Give up</button>
192+
<br><br><!-- These go in the last form if there's more than one: -->
193+
<pre id="correctStamp"></pre>
194+
<textarea id="debugData" class="displayNone" rows="20" cols="70" readonly>
195+
</textarea>
196+
</form>
197+
198+
</div><!-- End GitHub pages formatting -->
199+
</body>
200+
</html>

0 commit comments

Comments
 (0)