You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/labs/regex0.html
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -43,14 +43,14 @@ <h2>Background</h2>
43
43
<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>”.
44
44
Inside the brackets you can include
45
45
ranges of symbols separated by dash ("-"), so
46
-
<tt>[A-D]</tt> will match one character, which can be one A, one B, one C,
47
-
or one D.
48
-
You can do this more than once.
46
+
<tt>[A-D]</tt> will match one character in that range,
47
+
which can be one A, one B, one C, or one D.
48
+
You can provide more than one range inside brackets.
49
49
For example,
50
50
the term <tt>[A-Za-z]</tt> will match one character, which can be
51
51
an uppercase Latin letter or a lowercase Latin letter.
52
-
(This text assumes you're not using a long-obsolete character system
53
-
like EBCDIC.)
52
+
(For purposes of our labs we're
53
+
assuming you're not using a long-obsolete character system like EBCDIC.)
54
54
<li>If you follow a pattern with “<tt>*</tt>”, that means
55
55
“<i>0 or more times</i>”.
56
56
In almost all regex implementations (except POSIX BRE),
Copy file name to clipboardExpand all lines: docs/labs/regex1.js
+51-28Lines changed: 51 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -5,161 +5,184 @@ info =
5
5
present: "/",
6
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
7
examples: [
8
-
["/"]
8
+
["/"],
9
9
],
10
10
},
11
11
{
12
12
present: "[\"'`]",
13
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
14
examples: [
15
-
["'"]
15
+
["'"],
16
16
],
17
17
},
18
18
{
19
19
absent: String.raw`^\^`,
20
20
text: "For input validation, start with '^' to indicate a full match.",
21
21
examples: [
22
-
["(Y|N)"]
22
+
["(Y|N)"],
23
23
],
24
24
},
25
25
{
26
26
present: String.raw`\\[Zz]`,
27
27
text: "The ECMAScript (JavaScript) specification does not support \\Z or \\z.",
28
28
examples: [
29
-
["^Y|N\\z"]
29
+
["^Y|N\\z"],
30
30
],
31
31
},
32
32
{
33
33
absent: String.raw`\$$`,
34
34
text: "For input validation, end with '$' to indicate a full match.",
35
35
examples: [
36
-
["^(Y|N)"]
36
+
["^(Y|N)"],
37
37
],
38
38
},
39
39
{
40
40
absent: String.raw`[\|\[]`,
41
41
text: "Consider using [YN], to match either a Y or an N.",
42
42
examples: [
43
-
["^$"]
43
+
["^$"],
44
44
],
45
45
},
46
46
{
47
47
present: String.raw`\|`,
48
48
absent: String.raw`\(`,
49
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
50
examples: [
51
-
["^Y|N$"]
51
+
["^Y|N$"],
52
52
],
53
53
},
54
54
{
55
55
present: " ",
56
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
57
examples: [
58
-
["^[YN] $"]
58
+
["^[YN] $"],
59
59
],
60
60
},
61
61
{
62
62
absent: String.raw`^\^`,
63
63
index: 1,
64
64
text: "For input validation, start with '^' to indicate a full match.",
65
65
examples: [
66
-
["^[YN]$",""]
66
+
[null,""],
67
67
],
68
68
},
69
69
{
70
70
absent: String.raw`\$$`,
71
71
index: 1,
72
72
text: "For input validation, end with '$' to indicate a full match.",
73
73
examples: [
74
-
["^[YN]$","^"]
74
+
[null,"^"],
75
75
],
76
76
},
77
77
{
78
78
absent: String.raw`\[A-Z\]`,
79
79
index: 1,
80
80
text: "You can use [A-Z] to match one uppercase Latin letter (A through Z).",
81
81
examples: [
82
-
["^[YN]$","^$"]
82
+
[null,"^$"],
83
83
],
84
84
},
85
85
{
86
86
present: String.raw`\^\[A-Z\]\*`,
87
87
index: 1,
88
-
text: "A \"*\" matches one or more, not one or more."
88
+
text: "A \"*\" matches one or more, not one or more.",
89
+
examples: [
90
+
[null,"^[A-Z]*$"],
91
+
],
89
92
},
90
93
{
91
94
present: String.raw`\(`,
92
95
index: 1,
93
-
text: "You do not need parentheses to solve this problem."
96
+
text: "You do not need parentheses to solve this problem.",
97
+
examples: [
98
+
[null,"^([A-Z])+$"],
99
+
],
94
100
},
95
101
{
96
-
absent: String.raw`(\[A-Z\]\+|
97
-
\[A-Z\]\[A-Z\]\*)`,
102
+
absent: String.raw`\[A-Z\](\+|\[A-Z\]\*)`,
98
103
index: 1,
99
104
text: "You can use [A-Z]+ to match one or more uppercase Latin letters.",
100
105
examples: [
101
-
["^[YN]$","^[A-Z]$"]
106
+
[null,"^[A-Z]$"],
102
107
],
103
108
},
104
109
{
105
110
present: "True",
106
111
index: 2,
107
-
text: "Regular expressions are case-sensitive by default; use \"true\"."
112
+
text: "Regular expressions are case-sensitive by default; use \"true\"",
113
+
examples: [
114
+
[null,null,"True"],
115
+
],
108
116
},
109
117
{
110
118
present: "False",
111
119
index: 2,
112
-
text: "Regular expressions are case-sensitive by default; use \"false\"."
120
+
text: "Regular expressions are case-sensitive by default; use \"false\".",
121
+
examples: [
122
+
[null,null,"False"],
123
+
],
113
124
},
114
125
{
115
126
absent: String.raw`\|`,
116
127
index: 2,
117
-
text: "Use \"|\" to express alternatives."
128
+
text: "Use \"|\" to express alternatives.",
118
129
},
119
130
{
120
131
present: String.raw`^\^true\|false\$$`,
121
132
index: 2,
122
-
text: "No. This would match anything beginning with the term true, or anything ending with the term false. Use parenthesis."
133
+
text: "No. This would match anything beginning with the term true, or anything ending with the term false. Use parenthesis.",
123
134
},
124
135
{
125
136
present: String.raw`^\^false\|true\$$`,
126
137
index: 2,
127
-
text: "No. This would match anything beginning with the term false, or anything ending with the term true. Use parenthesis."
138
+
text: "No. This would match anything beginning with the term false, or anything ending with the term true. Use parenthesis.",
128
139
},
129
140
{
130
141
absent: String.raw`\(`,
131
142
index: 2,
132
-
text: "Use parentheses."
143
+
text: "Use parentheses.",
133
144
},
134
145
{
135
146
present: String.raw`\$`,
136
147
index: 3,
137
-
text: "This is Python, not ECMAScript (JavaScript). Use \\Z at the end, not $."
148
+
text: "This is Python, not ECMAScript (JavaScript). Use \\Z at the end, not $.",
149
+
examples: [
150
+
[null,null,null,"^[A-Z]+$"],
151
+
],
138
152
},
139
153
{
140
154
present: String.raw`\\z`,
141
155
index: 3,
142
-
text: "This is Python. Use \\Z at the end, not \\z."
156
+
text: "This is Python. Use \\Z at the end, not \\z.",
157
+
examples: [
158
+
[null,null,null,"^[A-Z]+\\z"],
159
+
],
143
160
},
144
161
{
145
162
absent: String.raw`^\\A`,
146
163
index: 4,
147
-
text: "This is Ruby. Use \\A at the beginning."
164
+
text: "This is Ruby. Use \\A at the beginning.",
165
+
examples: [
166
+
[null,null,null,null,"^[A-Z]+$"],
167
+
],
148
168
},
149
169
{
150
170
absent: String.raw`\\z$`,
151
171
index: 4,
152
-
text: "This is Ruby. Use \\z at the end."
172
+
text: "This is Ruby. Use \\z at the end.",
173
+
examples: [
174
+
[null,null,null,null,"\\A[A-Z]+$"],
175
+
],
153
176
},
154
177
{
155
178
absent: String.raw`\[A-Z\]`,
156
179
index: 4,
157
-
text: "Use [A-Z] to match one uppercase Latin letter."
180
+
text: "Use [A-Z] to match one uppercase Latin letter.",
158
181
},
159
182
{
160
183
present: String.raw`\[A-Z\](\*|\+)`,
161
184
index: 4,
162
-
text: "In this case we are only matching one letter, not many of them. Do not use \"*\" or \"+\" after [A-Z]."
185
+
text: "In this case we are only matching one letter, not many of them. Do not use \"*\" or \"+\" after [A-Z].",
0 commit comments