-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcourse-definition.yml
510 lines (364 loc) · 19.6 KB
/
course-definition.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
slug: "grep"
name: "Build your own grep"
short_name: "grep"
release_status: "live"
description_md: |-
Regular expressions (Regexes, for short) are patterns used to match character combinations in strings. In this
challenge you'll build your own implementation of grep, a CLI tool for searching using Regexes.
Along the way you'll learn about Regex syntax, character classes, quantifiers and more.
# Keep this under 70 characters
short_description_md: |-
Learn about regex syntax: character classes, quantifiers and more
completion_percentage: 30
languages:
- slug: "cpp"
- slug: "csharp"
- slug: "gleam"
- slug: "go"
- slug: "haskell"
- slug: "java"
- slug: "javascript"
- slug: "kotlin"
- slug: "php"
- slug: "python"
- slug: "rust"
- slug: "typescript"
- slug: "ruby"
release_status: "alpha"
alpha_tester_usernames: ["sreeram-venkitesh"]
marketing:
difficulty: medium
sample_extension_idea_title: "Lookahead assertions"
sample_extension_idea_description: "A grep implementation that can handle lookahead assertions like x(?=y)"
testimonials:
- author_name: "Ananthalakshmi Sankar"
author_description: "Automation Engineer at Apple"
author_avatar: "https://codecrafters.io/images/external/testimonials/oxta.jpeg"
link: "https://github.com/anu294"
text: "There are few sites I like as much that have a step by step guide. The real-time feedback is so good, it's creepy!"
- author_name: "Patrick Burris"
author_description: "Senior Software Developer, CenturyLink"
author_avatar: "https://codecrafters.io/images/external/testimonials/patrick-burris.jpeg"
link: "https://github.com/Jumballaya"
text: |-
I think the instant feedback right there in the git push is really cool.
Didn't even know that was possible!
extensions:
- slug: "backreferences"
name: "Backreferences"
description_markdown: |
In this challenge extension, you'll add support for [backreferences][1] to your Grep implementation.
Along the way, you'll learn about how capture groups and backreferences work.
[1]: https://learn.microsoft.com/en-us/dotnet/standard/base-types/backreference-constructs-in-regular-expressions#numbered-backreferences
stages:
- slug: "cq2"
name: "Match a literal character"
difficulty: very_easy
description_md: |-
In this stage, we'll handle the simplest regex possible: a single character.
**Example:** `a` should match "apple", but not "dog".
Your program will be executed like this:
```bash
$ echo -n "apple" | ./your_program.sh -E "a"
```
The `-E` flag instructs `grep` to interprets patterns as extended regular expressions (with support
for metacharacters like `+`, `?` etc.). We'll use this flag in all stages.
You program must [exit](https://en.wikipedia.org/wiki/Exit_status) with 0 if the character is found, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll handle the simplest regex possible: a single character.
**Example:**
`a` should match "apple", but not "dog".
- slug: "oq2"
name: "Match digits"
difficulty: very_easy
description_md: |-
In this stage, we'll implement support for the `\d`
[character class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes).
`\d` matches any digit.
**Example:** `\d` should match "3", but not "c".
Your program will be executed like this:
```bash
$ echo -n "apple123" | ./your_program.sh -E "\d"
```
You program must exit with 0 if a digit is found in the string, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll implement support for the `\d`
[character class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes).
`\d` matches any digit.
**Example:**
`\d` should match "1", but not "a".
- slug: "mr9"
name: "Match alphanumeric characters"
difficulty: very_easy
description_md: |-
In this stage, we'll implement support for the `\w`
[character class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes).
`\w` matches any alphanumeric character (`a-z`, `A-Z`, `0-9`, `_`).
**Example:** `\w` should match "foo101", but not "$!?".
Your program will be executed like this:
```bash
$ echo -n "alpha-num3ric" | ./your_program.sh -E "\w"
```
You program must exit with 0 if an alphanumeric character is found in the string, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll implement support for the `\w`
[character class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Character_Classes).
`\w` matches any alphanumeric character (`a-z`, `A-Z`, `0-9`, `_`).
**Example:**
`\w` should match "foo101", but not "$!?".
- slug: "tl6"
name: "Positive Character Groups"
difficulty: medium
description_md: |-
In this stage, we'll add support for [positive character groups](https://docs.microsoft.com/en-us/dotnet/standard/base-types/character-classes-in-regular-expressions#positive-character-group--).
Positive character groups match any character that is present within a pair of square brackets.
**Example:** `[abc]` should match "apple", but not "dog".
Your program will be executed like this:
```bash
$ echo -n "apple" | ./your_program.sh -E "[abc]"
```
You program must exit with 0 if an any of the characters are found in the string, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for [positive character groups](https://docs.microsoft.com/en-us/dotnet/standard/base-types/character-classes-in-regular-expressions#positive-character-group--).
Positive character groups match any character that is present within a pair of square brackets.
**Example:**
`[abc]` should match "apple", but not "dog".
- slug: "rk3"
name: "Negative Character Groups"
difficulty: medium
description_md: |-
In this stage, we'll add support for [negative character groups](https://docs.microsoft.com/en-us/dotnet/standard/base-types/character-classes-in-regular-expressions#negative-character-group-).
Negative character groups match any character that is not present within a pair of square brackets.
**Example:** `[^abc]` should match "dog", but not "cab" (since all characters are either "a", "b" or "c").
Your program will be executed like this:
```bash
$ echo -n "apple" | ./your_program.sh -E "[^abc]"
```
You program must exit with 0 if the input contains characters that aren't part of the negative character group, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for [negative character groups](https://docs.microsoft.com/en-us/dotnet/standard/base-types/character-classes-in-regular-expressions#negative-character-group-).
Negative character groups match any character that is not present within a pair of square brackets.
**Example:**
`[^abc]` should match "dog", but not "cab" (since all characters are either "a", "b" or "c").
- slug: "sh9"
name: "Combining Character Classes"
difficulty: medium
description_md: |-
In this stage, we'll add support for patterns that combine the character classes we've seen so far.
This is where your regex matcher will start to _feel_ useful.
Keep in mind that this stage is harder than the previous ones. You'll likely need to rework your
implementation to process user input character-by-character instead of the whole line at once.
We recommend taking a look at the example code in ["A Regular Expression Matcher"](https://www.cs.princeton.edu/courses/archive/spr09/cos333/beautiful.html)
by Rob Pike to guide your implementation.
**Examples:**
- `\d apple` should match "1 apple", but not "1 orange".
- `\d\d\d apple` should match "100 apples", but not "1 apple".
- `\d \w\w\ws` should match "3 dogs" and "4 cats" but not "1 dog" (because the "s" is not present at the end).
Your program will be executed like this:
```bash
$ echo -n "1 apple" | ./your_program.sh -E "\d apple"
```
You program must exit with 0 if the pattern matches the input, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll support patterns that combine the character classes we've seen so far.
**Examples:**
- `\d apple` should match "1 apple", but not "1 orange".
- `\d\d\d apple` should match "100 apples", but not "1 apple".
- `\d \w\w\ws` should match "3 dogs" and "4 cats" but not "1 dog" (because the "s" is not present at the end).
This stage is significantly harder than the previous ones. You'll likely need to rework your
implementation to process user input character-by-character instead of the whole line at once.
- slug: "rr8"
name: "Start of string anchor"
difficulty: medium
description_md: |-
In this stage, we'll add support for `^`, the [Start of String or Line anchor](https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions#start-of-string-or-line-).
`^` doesn't match a character, it matches the start of a line.
**Example:** `^log` should match "log", but not "slog".
Your program will be executed like this:
```bash
$ echo -n "log" | ./your_program.sh -E "^log"
```
You program must exit with 0 if the input starts with the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for `^`, the [Start of String or Line anchor](https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions#start-of-string-or-line-).
`^` doesn't match a character, it matches the start of a line.
**Example:**
`^log` should match "log", but not "slog".
- slug: "ao7"
name: "End of string anchor"
difficulty: medium
description_md: |-
In this stage, we'll add support for `$`, the [End of String or Line anchor](https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions#start-of-string-or-line-).
`$` doesn't match a character, it matches the end of a line.
**Example:** `dog$` should match "dog", but not "dogs".
Your program will be executed like this:
```bash
$ echo -n "dog" | ./your_program.sh -E "dog$"
```
You program must exit with 0 if the input matches the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for `$`, the [End of String or Line anchor](https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions#start-of-string-or-line-).
`$` doesn't match a character, it matches the end of a line.
**Example:**
`dog$` should match "dog", but not "dogs".
- slug: "fz7"
name: "Match one or more times"
difficulty: hard
description_md: |-
In this stage, we'll add support for `+`, the [one or more](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-one-or-more-times-) quantifier.
**Example**: `a+` should match "apple" and "SaaS", but not "dog".
Your program will be executed like this:
```bash
$ echo -n "caats" | ./your_program.sh -E "ca+ts"
```
You program must exit with 0 if the input matches the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for `+`, the [one or more](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-one-or-more-times-) quantifier.
**Example**:
- `a+` should match "apple" and "SaaS", but not "dog".
- slug: "ny8"
name: "Match zero or one times"
difficulty: hard
description_md: |-
In this stage, we'll add support for `?`, the [zero or one](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-one-or-more-times-) quantifier (also known as the "optional" quantifier).
**Example**: `dogs?` should match "dogs" and "dog", but not "cat".
Your program will be executed like this:
```bash
$ echo -n "dogs" | ./your_program.sh -E "dogs?"
```
You program must exit with 0 if the input matches the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for `?`, the [zero or one](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-one-or-more-times-) quantifier (also known as the "optional" quantifier).
**Example**:
- `dogs?` should match "dogs" and "dog", but not "cat".
- slug: "zb3"
name: "Wildcard"
difficulty: medium
description_md: |-
In this stage, we'll add support for `.`, which matches any character.
**Example**: `d.g` should match "dog", but not "cog".
Your program will be executed like this:
```bash
$ echo -n "dog" | ./your_program.sh -E "d.g"
```
You program must exit with 0 if the input matches the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for `.`, which matches any character.
**Example**:
- `d.g` should match "dog", but not "cog".
- slug: "zm7"
name: "Alternation"
difficulty: hard
description_md: |-
In this stage, we'll add support for the `|` keyword, which allows combining multiple patterns in an either/or fashion.
**Example**: `(cat|dog)` should match "dog" and "cat", but not "apple".
Your program will be executed like this:
```bash
$ echo -n "cat" | ./your_program.sh -E "(cat|dog)"
```
You program must exit with 0 if the input matches the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |-
In this stage, we'll add support for the `|` keyword, which allows combining multiple patterns in an either/or fashion.
**Example**:
- `(cat|dog)` should match "dog" and "cat", but not "apple".
# Backreferences
- slug: "sb5"
primary_extension_slug: "backreferences"
name: "Single Backreference"
difficulty: hard
description_md: |
In this stage, we'll add support for backreferences.
A backreference lets you reuse a captured group in a regular expression. It is denoted by `\` followed by a number, indicating the position of the captured group.
**Examples:**
- `(cat) and \1` should match "cat and cat", but not "cat and dog".
- `\1` refers to the first captured group, which is `(cat)`.
- `(\w+) and \1` should match "cat and cat" and "dog and dog", but not "cat and dog".
- `\1` refers to the first captured group, which is `(\w+)`.
Your program will be executed like this:
```
$ echo -n "<input>" | ./your_program.sh -E "<pattern>"
```
Your program must exit with 0 if the input matches the given pattern, and 1 if not.
**Note:** You only need to focus on one backreference and one capturing group in this stage. We'll get to handling multiple backreferences in the next stage.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |
In this stage, you'll add support for single backreferences. You'll implement support for `\1`.
**Example:**
- `(cat) and \1` should match "cat and cat", but not "cat and dog".
- slug: "tg1"
primary_extension_slug: "backreferences"
name: "Multiple Backreferences"
difficulty: medium
description_md: |
In this stage, we'll add support for multiple backreferences.
Multiple backreferences allow you to refer to several different captured groups within the same regex pattern.
**Example:** `(\d+) (\w+) squares and \1 \2 circles` should match "3 red squares and 3 red circles" but should not match "3 red squares and 4 red circles".
Your program will be executed like this:
```
$ echo -n "<input>" | ./your_program.sh -E "<pattern>"
```
Your program must exit with 0 if the input matches the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |
In this stage, you'll add support for multiple backreferences (`\1`, `\2` etc.) in the same pattern.
**Example:**
- `(\d+) (\w+) squares and \1 \2 circles` should match "3 red squares and 3 red circles" but should not match "3 red squares and 4 red circles".
- slug: "xe5"
primary_extension_slug: "backreferences"
name: "Nested Backreferences"
difficulty: hard
description_md: |
In this stage, we'll add support for nested backreferences. This means that a backreference is part of a larger capturing group, which itself is referenced again.
**Example:** `('(cat) and \2') is the same as \1` should match "'cat and cat' is the same as 'cat and cat'".
Your program will be executed like this:
```
$ echo -n "<input>" | ./your_program.sh -E "<pattern>"
```
Your program must exit with 0 if the input matches the given pattern, and 1 if not.
{{#reader_is_bot}}
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
{{/reader_is_bot}}
marketing_md: |
In this stage, you'll add support for nested backreferences.
**Example:**
- `('(cat) and \2') is the same as \1` should match "'cat and cat' is the same as 'cat and cat'".