Odpowiedzi regexp

This commit is contained in:
Aleksander Misztal 2020-01-25 11:09:37 +01:00
parent b74810884c
commit a4430c57ba
3 changed files with 29 additions and 0 deletions

9
regexp/Task301.py Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
def letter_and_two_digits(napis):
if re.search(r'[A-Z]\d{2}', napis):
return True
else:
return False

14
regexp/Task302.py Normal file
View File

@ -0,0 +1,14 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import re
def extract_minutes(string):
pattern = r'^([\d]|1[\d]|2[0-3]):([0-5][\d])$'
out = re.search(pattern, string)
if out is None:
return '<NONE>'
else:
return out.group(2)

6
regexp/Task303.py Normal file
View File

@ -0,0 +1,6 @@
import re
def divisable_by_four(string):
wyrazenie = '^[048]$|^[0-9]*([13579][26]|[2468][048])$|^[1-9][0-9]*(00|04|08)$'
return re.search(wyrazenie, string)