py-basic/src/tasks/regex.py
2023-09-05 16:15:17 +02:00

18 lines
419 B
Python

#!/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}.")