Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
129 commits
Select commit Hold shift + click to select a range
f4e30e9
New translations code.py (Romanian)
ninaszymor Mar 2, 2020
0d0c38e
New translations step_1.md (Danish)
ninaszymor Mar 2, 2020
a39521d
New translations code.py (Czech)
ninaszymor Mar 2, 2020
1bc2fc5
New translations .keep (Czech)
ninaszymor Mar 2, 2020
4f6020c
New translations meta.yml (Czech)
ninaszymor Mar 2, 2020
9324eff
New translations step_1.md (Czech)
ninaszymor Mar 2, 2020
461f85f
New translations code.py (Danish)
ninaszymor Mar 2, 2020
54c331b
New translations .keep (Danish)
ninaszymor Mar 2, 2020
35af01b
New translations meta.yml (Danish)
ninaszymor Mar 2, 2020
224d350
New translations code.py (German)
ninaszymor Mar 2, 2020
4095e70
New translations meta.yml (Catalan)
ninaszymor Mar 2, 2020
e55bf73
New translations .keep (German)
ninaszymor Mar 2, 2020
3e74acf
New translations meta.yml (German)
ninaszymor Mar 2, 2020
2aaef14
New translations step_1.md (German)
ninaszymor Mar 2, 2020
72beb62
New translations code.py (Greek)
ninaszymor Mar 2, 2020
4b96952
New translations .keep (Greek)
ninaszymor Mar 2, 2020
2eee3d4
New translations meta.yml (Greek)
ninaszymor Mar 2, 2020
d529472
New translations code.py (Finnish)
ninaszymor Mar 2, 2020
7198055
New translations .keep (Romanian)
ninaszymor Mar 2, 2020
8a0c006
New translations step_1.md (Catalan)
ninaszymor Mar 2, 2020
1cac588
New translations step_1.md (Greek)
ninaszymor Mar 2, 2020
2c690dd
New translations .keep (Catalan)
ninaszymor Mar 2, 2020
fa0b8f3
New translations meta.yml (Spanish)
ninaszymor Mar 2, 2020
302b75c
New translations step_1.md (Romanian)
ninaszymor Mar 2, 2020
d32b872
New translations meta.yml (Romanian)
ninaszymor Mar 2, 2020
5b17f75
New translations code.py (French)
ninaszymor Mar 2, 2020
8542238
New translations .keep (French)
ninaszymor Mar 2, 2020
0f8555d
New translations meta.yml (French)
ninaszymor Mar 2, 2020
b2427ab
New translations step_1.md (French)
ninaszymor Mar 2, 2020
9bcfb60
New translations .keep (Spanish)
ninaszymor Mar 2, 2020
037bc50
New translations code.py (Spanish)
ninaszymor Mar 2, 2020
ec32424
New translations step_1.md (Spanish)
ninaszymor Mar 2, 2020
d197e58
New translations code.py (Arabic)
ninaszymor Mar 2, 2020
deeb1e9
New translations step_1.md (Arabic)
ninaszymor Mar 2, 2020
6162e3c
New translations code.py (Afrikaans)
ninaszymor Mar 2, 2020
9cbda9d
New translations .keep (Arabic)
ninaszymor Mar 2, 2020
a6f4a0c
New translations meta.yml (Arabic)
ninaszymor Mar 2, 2020
c84b2c5
New translations step_1.md (Afrikaans)
ninaszymor Mar 2, 2020
d3a5a5d
New translations meta.yml (Afrikaans)
ninaszymor Mar 2, 2020
6b13cd4
New translations .keep (Afrikaans)
ninaszymor Mar 2, 2020
739d9c4
New translations code.py (Catalan)
ninaszymor Mar 2, 2020
20d5ba0
New translations code.py (Turkish)
ninaszymor Mar 2, 2020
da9b96a
New translations meta.yml (Ukrainian)
ninaszymor Mar 2, 2020
f645acd
New translations .keep (Ukrainian)
ninaszymor Mar 2, 2020
78066cc
New translations code.py (Ukrainian)
ninaszymor Mar 2, 2020
fe17083
New translations step_1.md (Turkish)
ninaszymor Mar 2, 2020
867eedc
New translations meta.yml (Turkish)
ninaszymor Mar 2, 2020
f5997e7
New translations .keep (Turkish)
ninaszymor Mar 2, 2020
6199a65
New translations step_1.md (Russian)
ninaszymor Mar 2, 2020
9a851a6
New translations step_1.md (Swedish)
ninaszymor Mar 2, 2020
3354620
New translations meta.yml (Swedish)
ninaszymor Mar 2, 2020
b61252c
New translations .keep (Swedish)
ninaszymor Mar 2, 2020
e6ea510
New translations code.py (Swedish)
ninaszymor Mar 2, 2020
abd9080
New translations step_1.md (Serbian (Cyrillic))
ninaszymor Mar 2, 2020
6d12ad3
New translations meta.yml (Serbian (Cyrillic))
ninaszymor Mar 2, 2020
e6d1ca7
New translations .keep (Serbian (Cyrillic))
ninaszymor Mar 2, 2020
af8cb86
New translations code.py (Serbian (Cyrillic))
ninaszymor Mar 2, 2020
34a7005
New translations step_1.md (Ukrainian)
ninaszymor Mar 2, 2020
b73b1d1
New translations .keep (English)
ninaszymor Mar 2, 2020
74e52ae
New translations code.py (Chinese Simplified)
ninaszymor Mar 2, 2020
e35580e
New translations code.py (Vietnamese)
ninaszymor Mar 2, 2020
e9d8ce5
New translations .keep (Russian)
ninaszymor Mar 2, 2020
cfbd7bd
New translations meta.yml (Portuguese, Brazilian)
ninaszymor Mar 2, 2020
8b6d4f1
New translations .keep (Portuguese, Brazilian)
ninaszymor Mar 2, 2020
27ea2ff
New translations code.py (Portuguese, Brazilian)
ninaszymor Mar 2, 2020
cdfbe00
New translations step_1.md (Vietnamese)
ninaszymor Mar 2, 2020
374b2ee
New translations meta.yml (Vietnamese)
ninaszymor Mar 2, 2020
eb2a9a7
New translations .keep (Vietnamese)
ninaszymor Mar 2, 2020
c4ce51c
New translations step_1.md (English)
ninaszymor Mar 2, 2020
275c154
New translations .keep (Chinese Simplified)
ninaszymor Mar 2, 2020
00755c1
New translations meta.yml (English)
ninaszymor Mar 2, 2020
5f62cf6
New translations code.py (English)
ninaszymor Mar 2, 2020
5b6599f
New translations step_1.md (Chinese Traditional)
ninaszymor Mar 2, 2020
fc526ef
New translations meta.yml (Chinese Traditional)
ninaszymor Mar 2, 2020
d48f4f3
New translations .keep (Chinese Traditional)
ninaszymor Mar 2, 2020
efcd6f8
New translations code.py (Chinese Traditional)
ninaszymor Mar 2, 2020
156755d
New translations step_1.md (Chinese Simplified)
ninaszymor Mar 2, 2020
5b7a6c3
New translations meta.yml (Chinese Simplified)
ninaszymor Mar 2, 2020
d7f02d6
New translations meta.yml (Russian)
ninaszymor Mar 2, 2020
b348b8b
New translations code.py (Korean)
ninaszymor Mar 2, 2020
745ac3e
New translations code.py (Russian)
ninaszymor Mar 2, 2020
7275acf
New translations .keep (Hungarian)
ninaszymor Mar 2, 2020
6b7d8f3
New translations code.py (Japanese)
ninaszymor Mar 2, 2020
f6a39f3
New translations step_1.md (Italian)
ninaszymor Mar 2, 2020
b7d252a
New translations meta.yml (Italian)
ninaszymor Mar 2, 2020
8842595
New translations .keep (Italian)
ninaszymor Mar 2, 2020
9b947ad
New translations code.py (Italian)
ninaszymor Mar 2, 2020
b41fc21
New translations step_1.md (Hungarian)
ninaszymor Mar 2, 2020
abcd40f
New translations meta.yml (Hungarian)
ninaszymor Mar 2, 2020
bf23faa
New translations code.py (Hungarian)
ninaszymor Mar 2, 2020
7568481
New translations meta.yml (Japanese)
ninaszymor Mar 2, 2020
075eb58
New translations step_1.md (Hebrew)
ninaszymor Mar 2, 2020
b720731
New translations meta.yml (Hebrew)
ninaszymor Mar 2, 2020
b4177c2
New translations .keep (Hebrew)
ninaszymor Mar 2, 2020
6763883
New translations code.py (Hebrew)
ninaszymor Mar 2, 2020
cdeebbe
New translations step_1.md (Finnish)
ninaszymor Mar 2, 2020
2f46297
New translations meta.yml (Finnish)
ninaszymor Mar 2, 2020
946f0b1
New translations .keep (Finnish)
ninaszymor Mar 2, 2020
a0b358e
New translations .keep (Japanese)
ninaszymor Mar 2, 2020
73fcbd6
New translations step_1.md (Japanese)
ninaszymor Mar 2, 2020
0077289
New translations step_1.md (Portuguese)
ninaszymor Mar 2, 2020
2fa845b
New translations step_1.md (Norwegian)
ninaszymor Mar 2, 2020
00e51c9
New translations meta.yml (Portuguese)
ninaszymor Mar 2, 2020
ffbb1ed
New translations .keep (Portuguese)
ninaszymor Mar 2, 2020
f5d7860
New translations code.py (Portuguese)
ninaszymor Mar 2, 2020
1e6764d
New translations step_1.md (Polish)
ninaszymor Mar 2, 2020
0b40325
New translations meta.yml (Polish)
ninaszymor Mar 2, 2020
186f7ed
New translations .keep (Polish)
ninaszymor Mar 2, 2020
8dfea5d
New translations code.py (Polish)
ninaszymor Mar 2, 2020
2dcb54d
New translations meta.yml (Norwegian)
ninaszymor Mar 2, 2020
df69ba5
New translations .keep (Korean)
ninaszymor Mar 2, 2020
3d7ca43
New translations .keep (Norwegian)
ninaszymor Mar 2, 2020
0fadee3
New translations code.py (Norwegian)
ninaszymor Mar 2, 2020
af82e7e
New translations step_1.md (Dutch)
ninaszymor Mar 2, 2020
166906f
New translations meta.yml (Dutch)
ninaszymor Mar 2, 2020
ce75237
New translations .keep (Dutch)
ninaszymor Mar 2, 2020
4bf8c3f
New translations code.py (Dutch)
ninaszymor Mar 2, 2020
9515c90
New translations step_1.md (Korean)
ninaszymor Mar 2, 2020
102d093
New translations meta.yml (Korean)
ninaszymor Mar 2, 2020
de2cdca
New translations step_1.md (Portuguese, Brazilian)
ninaszymor Mar 2, 2020
03ca950
New translations meta.yml (Dutch)
majamanojlovic Apr 26, 2020
a002f95
New translations code.py (Dutch)
majamanojlovic Apr 26, 2020
85d3881
New translations step_1.md (Dutch)
majamanojlovic Apr 26, 2020
a59a846
New translations .keep (Spanish, Latin America)
majamanojlovic Jul 28, 2020
a437277
New translations code.py (Spanish, Latin America)
majamanojlovic Jul 28, 2020
4b974f2
New translations meta.yml (Spanish, Latin America)
majamanojlovic Jul 28, 2020
9542f38
New translations step_1.md (Spanish, Latin America)
majamanojlovic Jul 28, 2020
e3d5e4d
New translations meta.yml (Spanish, Latin America)
sashamishcheriakova Feb 9, 2024
d446f93
New translations step_1.md (Spanish, Latin America)
sashamishcheriakova Feb 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions af-ZA/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Finding text between patterns with regex and Python
hero_image: images/banner.png
description: Finding text between patterns with regex
original_url: https://codeclubprojects.org/en-GB/scratch/rock-band
theme: red #possible values: blue, green, navy, orange, red, turquoise, violet, yellow
duration: 1 #possible values: 1, 2 or 3
listed: false
ingredient: true
copyedit: true
curriculum:
interests:
technologies: "python"
site_areas:
steps:
-
title: Finding text
14 changes: 14 additions & 0 deletions af-ZA/resources/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import re

text = '''
start
Here is a line
end
start
and here is some more
end'''

match = re.findall(r'(?<=start).*?(?=end)', text, flags=re.DOTALL)



1 change: 1 addition & 0 deletions af-ZA/solutions/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

111 changes: 111 additions & 0 deletions af-ZA/step_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
If you want to find text located between specific characters or sequences of characters, you can use Python's `re` module and the `findall()` method.

- Let's suppose you have the following string:

```python
text = 'start Here is a line end'
```

- Imagine you want to find all the text between `'start'` and `'end'`. Here's the regex search you might use to do so:

```python
import re
text = 'start Here is a line end'
matches = re.findall(r'start.*end', text)
```

- If you now check the `matches` variable in the interpreter, you will see that it is a list of the matches Python has found:

```python
>>> matches
['start Here is a line end']
```

- What happens if there is more than one match, like in the example below?

```python
import re
text = 'start Here is a line end start and here is some more end'
matches = re.findall(r'start.*end', text)
```

```python
>>> match
['start Here is a line end start and here is some more end']
```

- That wasn't what we wanted. This is because this regex is described as **greedy**. That means it searches the entire string before returning the match, and then returns all characters between the first `'start'` and the last `'end'`.

- To make the **regex** non-greedy, you need to use a `.*?` rather than `.*`.

```python
import re
text = 'start Here is a line end start and here is some more end'
matches = re.findall(r'start.*?end', text)
```

```python
>>> match
['start Here is a line end', 'start and here is some more end']
```

- Now the list has two elements in it.

- If you don't want Python to include the `start` and `end` words in the results, then you need to tell the **regex** to **look ahead** and **look behind**. There are two regex elements which will do that:

- `?<=` means **look ahead**. Use it to search for text **after** the match.

- `?=` means **look behind**. Use it to search for text **before** the match.

- For these elements to work, you need to surround them and the pattern you're looking for in brackets:

```python
match = re.findall(r'(?<=start).*?(?=end)', text)
```

```python
>>> match
[' Here is a line ', ' and here is some more ']
```

- What happens with strings spread across multiple lines, such as the one below?

```python
import re
text = '''
start
Here is a line
end
start
and here is some more
end'''

match = re.findall(r'(?<=start).*?(?=end)', text)
```

```python
>>> match
[]
```

- That's not what we wanted. The problem is that newlines (`\n`) stop the regex search. Adding a `flag` to the search can sort this out though:

```python
import re

text = '''
start
Here is a line
end
start
and here is some more
end'''

match = re.findall(r'(?<=start).*?(?=end)', text, flags=re.DOTALL)
```

```python
>>> match
['\nHere is a line\n', '\nand here is some more\n']
```

17 changes: 17 additions & 0 deletions ar-SA/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Finding text between patterns with regex and Python
hero_image: images/banner.png
description: Finding text between patterns with regex
original_url: https://codeclubprojects.org/en-GB/scratch/rock-band
theme: red #possible values: blue, green, navy, orange, red, turquoise, violet, yellow
duration: 1 #possible values: 1, 2 or 3
listed: false
ingredient: true
copyedit: true
curriculum:
interests:
technologies: "python"
site_areas:
steps:
-
title: Finding text
14 changes: 14 additions & 0 deletions ar-SA/resources/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import re

text = '''
start
Here is a line
end
start
and here is some more
end'''

match = re.findall(r'(?<=start).*?(?=end)', text, flags=re.DOTALL)



1 change: 1 addition & 0 deletions ar-SA/solutions/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

111 changes: 111 additions & 0 deletions ar-SA/step_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
If you want to find text located between specific characters or sequences of characters, you can use Python's `re` module and the `findall()` method.

- Let's suppose you have the following string:

```python
text = 'start Here is a line end'
```

- Imagine you want to find all the text between `'start'` and `'end'`. Here's the regex search you might use to do so:

```python
import re
text = 'start Here is a line end'
matches = re.findall(r'start.*end', text)
```

- If you now check the `matches` variable in the interpreter, you will see that it is a list of the matches Python has found:

```python
>>> matches
['start Here is a line end']
```

- What happens if there is more than one match, like in the example below?

```python
import re
text = 'start Here is a line end start and here is some more end'
matches = re.findall(r'start.*end', text)
```

```python
>>> match
['start Here is a line end start and here is some more end']
```

- That wasn't what we wanted. This is because this regex is described as **greedy**. That means it searches the entire string before returning the match, and then returns all characters between the first `'start'` and the last `'end'`.

- To make the **regex** non-greedy, you need to use a `.*?` rather than `.*`.

```python
import re
text = 'start Here is a line end start and here is some more end'
matches = re.findall(r'start.*?end', text)
```

```python
>>> match
['start Here is a line end', 'start and here is some more end']
```

- Now the list has two elements in it.

- If you don't want Python to include the `start` and `end` words in the results, then you need to tell the **regex** to **look ahead** and **look behind**. There are two regex elements which will do that:

- `?<=` means **look ahead**. Use it to search for text **after** the match.

- `?=` means **look behind**. Use it to search for text **before** the match.

- For these elements to work, you need to surround them and the pattern you're looking for in brackets:

```python
match = re.findall(r'(?<=start).*?(?=end)', text)
```

```python
>>> match
[' Here is a line ', ' and here is some more ']
```

- What happens with strings spread across multiple lines, such as the one below?

```python
import re
text = '''
start
Here is a line
end
start
and here is some more
end'''

match = re.findall(r'(?<=start).*?(?=end)', text)
```

```python
>>> match
[]
```

- That's not what we wanted. The problem is that newlines (`\n`) stop the regex search. Adding a `flag` to the search can sort this out though:

```python
import re

text = '''
start
Here is a line
end
start
and here is some more
end'''

match = re.findall(r'(?<=start).*?(?=end)', text, flags=re.DOTALL)
```

```python
>>> match
['\nHere is a line\n', '\nand here is some more\n']
```

17 changes: 17 additions & 0 deletions ca-ES/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
title: Finding text between patterns with regex and Python
hero_image: images/banner.png
description: Finding text between patterns with regex
original_url: https://codeclubprojects.org/en-GB/scratch/rock-band
theme: red #possible values: blue, green, navy, orange, red, turquoise, violet, yellow
duration: 1 #possible values: 1, 2 or 3
listed: false
ingredient: true
copyedit: true
curriculum:
interests:
technologies: "python"
site_areas:
steps:
-
title: Finding text
14 changes: 14 additions & 0 deletions ca-ES/resources/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import re

text = '''
start
Here is a line
end
start
and here is some more
end'''

match = re.findall(r'(?<=start).*?(?=end)', text, flags=re.DOTALL)



1 change: 1 addition & 0 deletions ca-ES/solutions/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading