Skip to content

Commit 0e267ec

Browse files
Lab regex1: Move answers to JavaScript
Signed-off-by: David A. Wheeler <[email protected]>
1 parent 774927f commit 0e267ec

File tree

2 files changed

+21
-78
lines changed

2 files changed

+21
-78
lines changed

docs/labs/regex1.html

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,84 +12,6 @@
1212

1313
<!-- See create_labs.md for how to create your own lab! -->
1414

15-
<!-- Sample expected answer -->
16-
<script id="expected0" type="plain/text">
17-
^[YN]$
18-
</script>
19-
20-
<!-- Full pattern of correct answer -->
21-
<script id="correct0" type="plain/text">
22-
\^(
23-
\[YN\]|
24-
\[NY\]|
25-
\( (\?\:)? Y\|N \)|
26-
\( (\?\:)? N\|Y \)
27-
)\$
28-
</script>
29-
30-
<!-- Sample expected answer -->
31-
<script id="expected1" type="plain/text">
32-
^[A-Z]+$
33-
</script>
34-
35-
<!-- Full pattern of correct answer -->
36-
<script id="correct1" type="plain/text">
37-
\^
38-
\[A-Z\]
39-
(\+|\[A-Z\]\*)
40-
\$
41-
</script>
42-
43-
<!-- Sample expected answer -->
44-
<script id="expected2" type="plain/text">
45-
^(true|false)$
46-
</script>
47-
48-
<!-- Full pattern of correct answer -->
49-
<script id="correct2" type="plain/text">
50-
\^\( (\?\:)?
51-
(
52-
true\|false|
53-
false\|true
54-
)\)\$
55-
</script>
56-
57-
<!-- Sample expected answer -->
58-
<script id="expected3" type="plain/text">
59-
^[A-Z]+\Z
60-
</script>
61-
62-
<!-- Full pattern of correct answer -->
63-
<script id="correct3" type="plain/text">
64-
\^
65-
\[A-Z\]
66-
(\+|\[A-Z\]\*)
67-
\\Z
68-
</script>
69-
70-
<!-- Sample expected answer.
71-
Only matches one Latin letters (A through Z), followed by a
72-
dash ("-"), followed by one or more digits.
73-
This time, do it for Ruby (not JavaScript or Python).
74-
-->
75-
<script id="expected4" type="plain/text">
76-
\A[A-Z]-[0-9]+\z
77-
</script>
78-
79-
<!-- Full pattern of correct answer -->
80-
<script id="correct4" type="plain/text">
81-
\\A
82-
\[A-Z\]
83-
-
84-
(\[0-9\]|\\d)
85-
(\+|(\[0-9\]|\\d)\*)
86-
\\z
87-
</script>
88-
89-
<!--
90-
91-
-->
92-
9315
</head>
9416
<body>
9517
<!-- For GitHub Pages formatting: -->

docs/labs/regex1.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,27 @@ info =
162162
text: "In this case we are only matching one letter, not many of them. Do not use \"*\" or \"+\" after [A-Z]."
163163
}
164164
],
165+
expected: [
166+
'^[YN]$',
167+
'^[A-Z]+$',
168+
'^(true|false)$',
169+
String.raw`^[A-Z]+\Z`,
170+
String.raw`\A[A-Z]-[0-9]+\z`,
171+
],
172+
correct: [
173+
String.raw`\^(
174+
\[YN\]|\[NY\]|
175+
\( (\?\:)? Y\|N \)|
176+
\( (\?\:)? N\|Y \) )\$`,
177+
String.raw`\^ \[A-Z\](\+|\[A-Z\]\*) \$`,
178+
String.raw`\^\( (\?\:)?
179+
(true\|false|false\|true)\)\$`,
180+
// Python uses \Z
181+
String.raw`\^ \[A-Z\] (\+|\[A-Z\]\*) \\Z`,
182+
// Ruby uses \A and \z
183+
String.raw`\\A \[A-Z\]-(\[0-9\]|\\d)
184+
(\+|(\[0-9\]|\\d)\*) \\z`,
185+
],
165186
preprocessing: [
166187
[
167188
"\\s*",

0 commit comments

Comments
 (0)