regex stuff
This commit is contained in:
parent
2e23190dfe
commit
7d1c18101a
4
Tasks.md
4
Tasks.md
|
@ -242,7 +242,7 @@ The text is large, read it [here](data/metasyntactic.md) and find the raw text f
|
|||
|
||||
</details>
|
||||
|
||||
1. Use a regular expression (regex) to find all instances of a lowercase character with a
|
||||
1. Use a regular expression (regex) to find all words that start with a lowercase character with a
|
||||
following vowel character, in which no 'x', z' or 'y' follows the vowel in the given Text.
|
||||
It is not allowed to store the text in source code, you must load it from an outside source,
|
||||
such as a file.
|
||||
|
@ -252,6 +252,8 @@ Examples:
|
|||
| Original | is Match? |
|
||||
|----------|-----------|
|
||||
| foo | yes |
|
||||
| foobar | yes |
|
||||
| tayfoo | no |
|
||||
| baz | no |
|
||||
| qux | no |
|
||||
| Foo | no |
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/env python3
|
||||
import re
|
||||
import sys
|
||||
|
||||
if len(sys.argv) != 2:
|
||||
print("takes only a file path as argument")
|
||||
exit(1)
|
||||
|
||||
textfile = open(sys.argv[1])
|
||||
text = textfile.read()
|
||||
|
||||
regex = r"\b[a-z][AEIOUaeiou]([a-w]|[A-W])"
|
||||
matches = re.finditer(regex, text, re.MULTILINE)
|
||||
counter = 0
|
||||
for i, match in enumerate(matches, start=1):
|
||||
#print(f"{i:03} | \"{match.string}\"")
|
||||
counter += 1
|
||||
print(f"found {counter}.")
|
Loading…
Reference in New Issue