|
21 | 21 | \^(
|
22 | 22 | \[YN\]|
|
23 | 23 | \[NY\]|
|
24 |
| -\(Y\|N\)| |
25 |
| -\(N\|Y\) |
| 24 | +\( (\?\:)? Y\|N \)| |
| 25 | +\( (\?\:)? N\|Y \) |
26 | 26 | )\$
|
27 | 27 | </script>
|
28 | 28 |
|
|
46 | 46 |
|
47 | 47 | <!-- Full pattern of correct answer -->
|
48 | 48 | <script id="correct2" type="plain/text">
|
49 |
| -\^\(( |
| 49 | +\^\( (\?\:)? |
| 50 | +( |
50 | 51 | true\|false|
|
51 | 52 | false\|true
|
52 | 53 | )\)\$
|
|
65 | 66 | \\Z
|
66 | 67 | </script>
|
67 | 68 |
|
| 69 | +<!-- Sample expected answer. |
| 70 | +Only matches one Latin letters (A through Z), followed by a |
| 71 | +dash ("-"), followed by one or more digits. |
| 72 | +This time, do it for Ruby (not JavaScript or Python). |
| 73 | + --> |
| 74 | +<script id="expected4" type="plain/text"> |
| 75 | +\A[A-Z]-[0-9]+\z |
| 76 | +</script> |
| 77 | + |
| 78 | +<!-- Full pattern of correct answer --> |
| 79 | +<script id="correct4" type="plain/text"> |
| 80 | +\\A |
| 81 | +\[A-Z\] |
| 82 | +- |
| 83 | +(\[0-9\]|\\d) |
| 84 | +(\+|(\[0-9\]|\\d)\*) |
| 85 | +\\z |
| 86 | +</script> |
| 87 | + |
68 | 88 | <script id="info" type="application/yaml">
|
69 | 89 | ---
|
70 | 90 | hints:
|
|
93 | 113 | absent: |-
|
94 | 114 | \(
|
95 | 115 | text: If you use "|" you must parentheses or the precedence will be wrong.
|
| 116 | + For example, "^A|B$" accepts anything beginning with A, and it also |
| 117 | + accepts anything ending with B. That is not what you want. |
96 | 118 | examples:
|
97 | 119 | - - "^Y|N$"
|
98 | 120 | - present: " "
|
99 |
| - text: Spaces normally match spaces in a regex; do not use them in this case. |
| 121 | + text: Spaces normally match spaces in a regex. Do not use them in this case, |
| 122 | + because a space is not one of the allowed characters. |
100 | 123 | examples:
|
101 | 124 | - - "^[YN] $"
|
102 | 125 | - absent: |-
|
|
150 | 173 | \|
|
151 | 174 | index: 2
|
152 | 175 | text: Use "|" to express alternatives.
|
| 176 | +- present: |- |
| 177 | + ^\^true\|false\$$ |
| 178 | + index: 2 |
| 179 | + text: No. This would match anything beginning with the term true, |
| 180 | + or anything ending with the term false. Use parenthesis. |
| 181 | +- present: |- |
| 182 | + ^\^false\|true\$$ |
| 183 | + index: 2 |
| 184 | + text: No. This would match anything beginning with the term false, |
| 185 | + or anything ending with the term true. Use parenthesis. |
153 | 186 | - absent: |-
|
154 | 187 | \(
|
155 | 188 | index: 2
|
|
162 | 195 | \\z
|
163 | 196 | index: 3
|
164 | 197 | text: This is Python. Use \Z at the end, not \z.
|
| 198 | +- absent: |- |
| 199 | + ^\\A |
| 200 | + index: 4 |
| 201 | + text: This is Ruby. Use \A at the beginning. |
| 202 | +- absent: |- |
| 203 | + \\z$ |
| 204 | + index: 4 |
| 205 | + text: This is Ruby. Use \z at the beginning. |
| 206 | +- absent: |- |
| 207 | + \[A-Z\] |
| 208 | + index: 4 |
| 209 | + text: Use [A-Z] to match one uppercase Latin letter. |
| 210 | +- present: |- |
| 211 | + \[A-Z\](\*|\+) |
| 212 | + index: 4 |
| 213 | + text: In this case we are only matching one letter, not many of them. |
| 214 | + Do not use "*" or "+" after [A-Z]. |
165 | 215 | # successes:
|
166 | 216 | # - - " query ( 'id' ) . isInt ( {min: 1 , max: 9999 } ) ,"
|
167 | 217 | # - - " query ( `id` ) . isInt ( {min: 1 , max: 9_999 } ) , "
|
@@ -292,6 +342,25 @@ <h3>Part 4</h2>
|
292 | 342 | <button type="button" class="giveUpButton">Give up</button>
|
293 | 343 | </form>
|
294 | 344 |
|
| 345 | +<h3>Part 5</h2> |
| 346 | +<p> |
| 347 | +Create a regular expression |
| 348 | +that only matches one Latin letter (A through Z), followed by a |
| 349 | +dash ("-"), followed by one or more digits. |
| 350 | +This time, do it for Ruby (not JavaScript or Python). |
| 351 | +<!-- |
| 352 | +You can use this an example for new labs. |
| 353 | +For multi-line inputs, instead of <input id="attempt0" type="text" ...>, use |
| 354 | +<textarea id="attempt" rows="2" cols="70">...</textarea> |
| 355 | +--> |
| 356 | +<form id="lab5"> |
| 357 | +<pre></code> |
| 358 | +<input id="attempt4" type="text" size="70" spellcheck="false" value=""> |
| 359 | +</code></pre> |
| 360 | +<button type="button" class="hintButton">Hint</button> |
| 361 | +<button type="button" class="resetButton">Reset</button> |
| 362 | +<button type="button" class="giveUpButton">Give up</button> |
| 363 | +</form> |
295 | 364 |
|
296 | 365 |
|
297 | 366 | <br><br><!-- These go in the last form if there's more than one: -->
|
|
0 commit comments