From 49ac444a19c04d94ff58926e7a067f1b4e9def57 Mon Sep 17 00:00:00 2001 From: "@ulazho" Date: Sun, 12 Nov 2023 19:27:38 +0100 Subject: [PATCH] hm2 --- lab-02/in.txt | 1 + lab-02/out.txt | 1 + lab-02/zadanie-1.py | 17 ++++++++--------- lab-02/zadanie-2.py | 18 ++++++++---------- lab-02/zadanie-3.py | 20 ++++++++++++-------- lab-02/zadanie-4.py | 10 ++++++++-- lab-02/zadanie-5.py | 14 ++++++++------ 7 files changed, 46 insertions(+), 35 deletions(-) create mode 100644 lab-02/in.txt create mode 100644 lab-02/out.txt diff --git a/lab-02/in.txt b/lab-02/in.txt new file mode 100644 index 0000000..7b593ae --- /dev/null +++ b/lab-02/in.txt @@ -0,0 +1 @@ +asdasdas9@assd \ No newline at end of file diff --git a/lab-02/out.txt b/lab-02/out.txt new file mode 100644 index 0000000..c1f22fb --- /dev/null +++ b/lab-02/out.txt @@ -0,0 +1 @@ +False \ No newline at end of file diff --git a/lab-02/zadanie-1.py b/lab-02/zadanie-1.py index 5a29510..731aee5 100644 --- a/lab-02/zadanie-1.py +++ b/lab-02/zadanie-1.py @@ -1,12 +1,11 @@ import re -tekst = """ -Jan: 12-452 -Anna: 987 65 -Karol: 456-78 -Zbyszek: 53252525342252 -Tytus: aaaa666432 -""" -wzorzec = re.compile(r"\d\d-\d\d\d") -print(f'Numery: {wzorzec.findall(tekst)}') \ No newline at end of file +fin = open('in.txt', 'r') +fout = open('out.txt', 'w') + +for line in fin.readlines(): + wzorzec = re.compile(r"\d\d-\d\d\d") + if bool(wzorzec.findall(line)): + for postcode in wzorzec.findall(line): + fout.write(postcode + ' ') \ No newline at end of file diff --git a/lab-02/zadanie-2.py b/lab-02/zadanie-2.py index 43fb387..988c5a3 100644 --- a/lab-02/zadanie-2.py +++ b/lab-02/zadanie-2.py @@ -1,13 +1,11 @@ import re -tekst = """ -Jan: https://regex101.com/ -Anna: 987 65 -Karol: 456-78 -Zbyszek: 53252525342252 -Tytus: aaaa666432 -https://git.wmi.amu.edu.pl/ -""" -wzorzec = re.compile(r"(https|http):\/\/(www.)?[\d\w]+\.\w+[^.]*") -print(f'Numery: {wzorzec.findall(tekst)}') \ No newline at end of file + +fin = open('in.txt', 'r') +fout = open('out.txt', 'w') + +url = fin.readline() + +wzorzec = re.compile(r"^(https?://)?([a-zA-Z0-9-]+\.){1,}[a-zA-Z]{2,}(/\S*)?$") +fout.write(str(bool(wzorzec.match(url)))) \ No newline at end of file diff --git a/lab-02/zadanie-3.py b/lab-02/zadanie-3.py index 8a9c7bd..bd29e1b 100644 --- a/lab-02/zadanie-3.py +++ b/lab-02/zadanie-3.py @@ -1,12 +1,16 @@ import re -tekst = """ -Jan: https://regex101.com/ -Anna: 987 65 -Karol: 456-78 -Zbyszek: 12345678901 -Tytus: aaaa666432 -""" +fin = open('in.txt', 'r') +fout = open('out.txt', 'w') + +pesel = fin.readline() + +if len(pesel) != 11: + fout.write('False') + exit() wzorzec = re.compile(r"\d{11}") -print(f'Numery: {wzorzec.findall(tekst)}') \ No newline at end of file + +if wzorzec.match(pesel): + fout.write('True') +else: fout.write('False') diff --git a/lab-02/zadanie-4.py b/lab-02/zadanie-4.py index ccffd80..6ce9737 100644 --- a/lab-02/zadanie-4.py +++ b/lab-02/zadanie-4.py @@ -4,9 +4,15 @@ tekst = """ Jan: https://regex101.com/ Anna: 987 65 Karol: 456-78 <\a> -Zbyszek: 12345678901 + Zbyszek: 12345678901 Tytus: aaaa666432 """ +fin = open('in.txt', 'r') +fout = open('out.txt', 'w') + wzorzec = re.compile(r"<[^>]*>") -print(f'Numery: {wzorzec.findall(tekst)}') \ No newline at end of file + +for line in fin.readlines(): + for tag in wzorzec.findall(line): + fout.write(tag + ' ') \ No newline at end of file diff --git a/lab-02/zadanie-5.py b/lab-02/zadanie-5.py index 48226c5..2e3a9c3 100644 --- a/lab-02/zadanie-5.py +++ b/lab-02/zadanie-5.py @@ -1,10 +1,12 @@ import re -tekst = """ -asdasdas9@asSd -as@d@asjdioajsd7y7asdSa1 -dioajsd7y7asdSa1 -""" +fin = open('in.txt', 'r') +fout = open('out.txt', 'w') + +password = fin.readline() wzorzec = re.compile(r"(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[@#$%&*!]).{8,}") -print(f'{wzorzec.findall(tekst)}') \ No newline at end of file + +if wzorzec.findall(password): + fout.write('True') +else: fout.write('False') \ No newline at end of file