add regex exercises

This commit is contained in:
Grzegorz Rogozik 2020-01-12 13:28:13 +01:00
parent bbb53ff4e2
commit a6d06c4f53
4 changed files with 35 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'^([0-9]|1[0-9]|2[0-3]):([0-5][0-9])$'
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):
pattern = '^[048]$|^[0-9]*([13579][26]|[2468][048])$|^[1-9][0-9]*(00|04|08)$'
return re.search(pattern, string)

6
regexp/Task328.py Normal file
View File

@ -0,0 +1,6 @@
import re
def is_hmmmm(string):
pattern = r'^hm{2,}(\.{3,}|)$'
return re.search(pattern, string)