From a6d06c4f538631cdeec6a9fbcd7d936344b1d5c0 Mon Sep 17 00:00:00 2001 From: Grzegorz Rogozik Date: Sun, 12 Jan 2020 13:28:13 +0100 Subject: [PATCH] add regex exercises --- regexp/Task301.py | 9 +++++++++ regexp/Task302.py | 14 ++++++++++++++ regexp/Task303.py | 6 ++++++ regexp/Task328.py | 6 ++++++ 4 files changed, 35 insertions(+) create mode 100644 regexp/Task301.py create mode 100644 regexp/Task302.py create mode 100644 regexp/Task303.py create mode 100644 regexp/Task328.py diff --git a/regexp/Task301.py b/regexp/Task301.py new file mode 100644 index 0000000..ec0e314 --- /dev/null +++ b/regexp/Task301.py @@ -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 diff --git a/regexp/Task302.py b/regexp/Task302.py new file mode 100644 index 0000000..25d688d --- /dev/null +++ b/regexp/Task302.py @@ -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 '' + else: + return out.group(2) diff --git a/regexp/Task303.py b/regexp/Task303.py new file mode 100644 index 0000000..e9f3ab9 --- /dev/null +++ b/regexp/Task303.py @@ -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) diff --git a/regexp/Task328.py b/regexp/Task328.py new file mode 100644 index 0000000..a114c04 --- /dev/null +++ b/regexp/Task328.py @@ -0,0 +1,6 @@ +import re + + +def is_hmmmm(string): + pattern = r'^hm{2,}(\.{3,}|)$' + return re.search(pattern, string)