This commit is contained in:
@ulazho 2023-11-12 19:27:38 +01:00
parent 8b35883eaa
commit 49ac444a19
7 changed files with 46 additions and 35 deletions

1
lab-02/in.txt Normal file
View File

@ -0,0 +1 @@
asdasdas9@assd

1
lab-02/out.txt Normal file
View File

@ -0,0 +1 @@
False

View File

@ -1,12 +1,11 @@
import re 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") fin = open('in.txt', 'r')
print(f'Numery: {wzorzec.findall(tekst)}') 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 + ' ')

View File

@ -1,13 +1,11 @@
import re 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)}') 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))))

View File

@ -1,12 +1,16 @@
import re import re
tekst = """ fin = open('in.txt', 'r')
Jan: https://regex101.com/ fout = open('out.txt', 'w')
Anna: 987 65
Karol: 456-78 pesel = fin.readline()
Zbyszek: 12345678901
Tytus: aaaa666432 if len(pesel) != 11:
""" fout.write('False')
exit()
wzorzec = re.compile(r"\d{11}") wzorzec = re.compile(r"\d{11}")
print(f'Numery: {wzorzec.findall(tekst)}')
if wzorzec.match(pesel):
fout.write('True')
else: fout.write('False')

View File

@ -4,9 +4,15 @@ tekst = """
Jan: https://regex101.com/ Jan: https://regex101.com/
Anna: 987 65 Anna: 987 65
Karol: 456-78 <\a> Karol: 456-78 <\a>
Zbyszek: 12345678901 <asdasd> <asd> Zbyszek: 12345678901 <asdasd>
Tytus: aaaa666432 Tytus: aaaa666432
""" """
fin = open('in.txt', 'r')
fout = open('out.txt', 'w')
wzorzec = re.compile(r"<[^>]*>") wzorzec = re.compile(r"<[^>]*>")
print(f'Numery: {wzorzec.findall(tekst)}')
for line in fin.readlines():
for tag in wzorzec.findall(line):
fout.write(tag + ' ')

View File

@ -1,10 +1,12 @@
import re import re
tekst = """ fin = open('in.txt', 'r')
asdasdas9@asSd fout = open('out.txt', 'w')
as@d@asjdioajsd7y7asdSa1
dioajsd7y7asdSa1 password = fin.readline()
"""
wzorzec = re.compile(r"(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[@#$%&*!]).{8,}") wzorzec = re.compile(r"(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])(?=.*[@#$%&*!]).{8,}")
print(f'{wzorzec.findall(tekst)}')
if wzorzec.findall(password):
fout.write('True')
else: fout.write('False')