Skip to content

Commit 1d4b4bb

Browse files
Merge pull request #138 from codecrafters-io/quantifiers
Quantifiers
2 parents e71ff77 + f21facd commit 1d4b4bb

File tree

5 files changed

+126
-1
lines changed

5 files changed

+126
-1
lines changed

course-definition.yml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ extensions:
6868
6969
Along the way, you'll learn about how to implement efficient file I/O, directory traversal and pattern matching on file contents.
7070
71+
- slug: "quantifiers"
72+
name: "Quantifiers"
73+
description_markdown: |
74+
In this challenge extension, you'll add support for [quantifiers][1] to your Grep implementation.
75+
76+
Along the way, you'll learn about how to implement the `*` quantifier (zero or more), and bounded quantifiers.
77+
[1]: https://learn.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions
78+
7179
stages:
7280
- slug: "cq2"
7381
name: "Match a literal character"
@@ -266,4 +274,33 @@ stages:
266274
name: "Recursive search"
267275
difficulty: hard
268276
marketing_md: |-
269-
In this stage, you'll add support for searching through files in a given directory and its subdirectories recursively with the -r flag.
277+
In this stage, you'll add support for searching through files in a given directory and its subdirectories recursively with the -r flag.
278+
279+
# Quantifiers
280+
- slug: "ai9"
281+
primary_extension_slug: "quantifiers"
282+
name: "Zero or more times"
283+
difficulty: hard
284+
marketing_md: |-
285+
In this stage, we'll add support for `*`, the [zero or more](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-zero-or-more-times-) quantifier.
286+
287+
- slug: "wy9"
288+
primary_extension_slug: "quantifiers"
289+
name: "Exact repetition"
290+
difficulty: hard
291+
marketing_md: |-
292+
In this stage, we'll add support for `{n}`, the [exact repetition](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-exactly-n-times-n) quantifier.
293+
294+
- slug: "hk3"
295+
primary_extension_slug: "quantifiers"
296+
name: "Minimum repetition"
297+
difficulty: hard
298+
marketing_md: |-
299+
In this stage, we'll add support for `{n,}`, the [at least m times](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-at-least-n-times-n) quantifier.
300+
301+
- slug: "ug0"
302+
primary_extension_slug: "quantifiers"
303+
name: "Range repetition"
304+
difficulty: hard
305+
marketing_md: |-
306+
In this stage, we'll add support for `{n,m}`, the [between n and m times](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-between-n-and-m-times-nm) quantifier.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
In this stage, we'll add support for `*`, the [zero or more](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-zero-or-more-times-) quantifier.
2+
3+
The `*` quantifier matches the preceding element zero or more times. This means the element can be absent entirely or repeated any number of times.
4+
5+
**Examples**:
6+
- `ca*t` should match "ct", "cat", and "caaat", but not "dog".
7+
- `k\d*t` should match "kt", "k1t", "k123t", and "k999t", but not "kabct".
8+
- `k[abc]*t` should match "kt", "kat", "kabct", and "kcccbbbt", but not "kaxyzt" or "kxyzt".
9+
10+
## Tests
11+
12+
Your program will be executed like this:
13+
14+
```bash
15+
$ echo -n "<input>" | ./your_program.sh -E "<pattern>"
16+
```
17+
18+
Your program must exit with 0 if the input matches the given pattern, and 1 if not.
19+
20+
{{#reader_is_bot}}
21+
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
22+
{{/reader_is_bot}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
In this stage, we'll add support for `{n}`, the [exact repetition](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-exactly-n-times-n) quantifier.
2+
3+
The `{n}` quantifier matches the preceding element exactly n times. The element must appear the exact number of times specified.
4+
5+
**Examples**:
6+
- `ca{3}t` should match "caaat", but not "caat" or "caaaat".
7+
- `d\d{2}g` should match "d42g" and "d99g", but not "d1g" or "d123g".
8+
- `c[xyz]{4}w` should match "cyyyyw" and "czyxzw", but not "cxyzw" or "xyzzzw".
9+
10+
## Tests
11+
12+
Your program will be executed like this:
13+
14+
```bash
15+
$ echo -n "<input>" | ./your_program.sh -E "<pattern>"
16+
```
17+
18+
Your program must exit with 0 if the input matches the given pattern, and 1 if not.
19+
20+
{{#reader_is_bot}}
21+
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
22+
{{/reader_is_bot}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
In this stage, we'll add support for `{n,}`, the [at least n times](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-at-least-n-times-n) quantifier.
2+
3+
The `{n,}` quantifier matches the preceding element at least n times. The element must appear n or more times, with no upper limit.
4+
5+
**Examples**:
6+
- `ca{2,}t` should match "caat", "caaat", and "caaaaat", but not "cat".
7+
- `x\d{3,}y` should match "x123y", "x9999y", and "x12345y", but not "x42y".
8+
- `b[aeiou]{2,}r` should match "baer", "baeiour", and "beeeeer", but not "bar".
9+
10+
## Tests
11+
12+
Your program will be executed like this:
13+
14+
```bash
15+
$ echo -n "<input>" | ./your_program.sh -E "<pattern>"
16+
```
17+
18+
Your program must exit with 0 if the input matches the given pattern, and 1 if not.
19+
20+
{{#reader_is_bot}}
21+
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
22+
{{/reader_is_bot}}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
In this stage, we'll add support for `{n,m}`, the [between n and m times](https://docs.microsoft.com/en-us/dotnet/standard/base-types/quantifiers-in-regular-expressions#match-between-n-and-m-times-nm) quantifier.
2+
3+
The `{n,m}` quantifier matches the preceding element between n and m times (inclusive). The element must appear at least n times but no more than m times.
4+
5+
**Examples**:
6+
- `ca{2,4}t` should match "caat", "caaat", and "caaaat", but not "cat" or "caaaaat".
7+
- `n\d{1,3}m` should match "n1m", "n42m", and "n123m", but not "n1234m".
8+
- `p[xyz]{2,3}q` should match "pxyq", "pxyzq", and "pzzzq", but not "pxq" or "pxyzyq".
9+
10+
## Tests
11+
12+
Your program will be executed like this:
13+
14+
```bash
15+
$ echo -n "<input>" | ./your_program.sh -E "<pattern>"
16+
```
17+
18+
Your program must exit with 0 if the input matches the given pattern, and 1 if not.
19+
20+
{{#reader_is_bot}}
21+
Do not use `grep` or the regex utilities available in the standard library. Implement the regex matcher yourself.
22+
{{/reader_is_bot}}

0 commit comments

Comments
 (0)