From 5b5a64fdadac3326b14a14ee880c710409e23013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20=C5=81ukasik?= Date: Mon, 9 Nov 2026 12:45:09 +0100 Subject: [PATCH] regex --- Lekcja_05/config.php | 2 + Lekcja_05/edit.php | 14 ++++- Lekcja_06/cwiczenia.md | 139 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 Lekcja_06/cwiczenia.md diff --git a/Lekcja_05/config.php b/Lekcja_05/config.php index add0deb..93e759a 100644 --- a/Lekcja_05/config.php +++ b/Lekcja_05/config.php @@ -1,6 +1,8 @@ Na zaplanowałem:


+ + + $plany_r = $plany_q->get_result()->fetch_assoc(); + echo @$plany_r['value']; + + mysqli_close($conn); + ?>
diff --git a/Lekcja_06/cwiczenia.md b/Lekcja_06/cwiczenia.md new file mode 100644 index 0000000..a3140b0 --- /dev/null +++ b/Lekcja_06/cwiczenia.md @@ -0,0 +1,139 @@ +Exercise 1: Develop a regular expression for any binary string. + +[0-1]* + +--- + +Exercise 2: Develop a regular expression for any binary string that represents an unsigned integer that is EVEN: + +[0-1]*0 + +--- + +Exercise 3: Develop a regular expression for any binary string of EVEN length: (Hint: remember the (cat)+ example?) + +([0-1][0-1])+ + +--- + +Exercise 4: Develop a regular expression for any binary string that contains the pattern 0110 OR the pattern 1001: + +.*(0110|1001).* + +--- + +Exercise 5: Develop a regular expression for any binary string that contains the pattern 0110 AND the pattern 1001: (Hint: There are 4 cases, not 2). + +*(011001|100110|0110.*1001|1001.*0110).* + +--- + +Exercise 6: Identify what types of strings the regular expression [A-Z][0-9][A-Z]\s[0-9][A-Z][0-9] represents, and give some test strings: + +Duża litera, cyfra od 0 do 9, duża litera, spacja, cyfra od 0 do 9, duża litera, cyfra od 0 do 9 +A4A 8U8 +B6Z 4Z0 +D3A 7J8 + +--- + +Exercise 7: Identify what types of strings the regular expression ([0-9]|[A-F])+ represents, and give some test strings: + +liczby w systemie szesnastkowym +F0F0F0 +ABCDEF +1234DD + +--- + +Exercise 8: Identify what types of strings the regular expression (\(\d\d\d\)\s)?\d\d\d-\d\d\d\d represents, and give some test strings: + +amerykancki numer telefonu +123-1234 +(123) 123-1234 +(420) 420-2137 + +--- + +Exercise 9: Develop a regular expression that will accept the following three strings: {"pickup truck", "pick up truck", "pick-up truck"}: + +pick[-\s]?up truck + +--- + +Exercise 10: Develop a regular expression that will accept three or four words: + +(\S+\s){2,3}\S+ + +--- +Exercise 11: Develop a regular expression that will accept the word cat and the word hat with at most 2 other words between them: + +cat\s(\S+\s){0,2}hat + +--- + +Exercise 12: Develop a regular expression that will accept a properly formatted 24-hour time (0:00 ... 23:59): + +(1?[0-9]|2[0-3]):[0-5][0-9] + +--- + +Exercise 13: (2 marks) Gene Identification + +DNA sequences are comprised of a simple 4-alphabet language with the symbols {A,C,G,T}. Three consecutive letters are known as a codon, so ACT and TCG are both codons. A Gene is a collection of at least three codons that starts with an ATG codon and ends with a TAA, TAG, or TGA codon. + +You need to develop a regular expression that will match strings that contain a gene. + +.*ATG([CTAG]{3})+(TAA|TAG|TGA).* + +--- + +Exercise 14: (2 marks) Money Matters + +Develop a regular expression that will accept a dollar amount. For example, $3.56 and $1,000,000 are valid amounts, whereas $5.321 and $5,29,40 are not. + +\$([0-9]+(\.[0-9][0-9])?|[0-9]{1,3}(\,[0-9]{3})*(\.[0-9][0-9])?) + +Mamy tu instrukcję or żeby zezwolć na $1000.00 ale na przykład już nie na $1000,123.00 + +--- + +Exercise 15: (2 marks) Testing Regular Expressions + +Your co-worker has been assigned the task of writing a regular expression that tests to see if an email address is valid: [a-z]*@([a-z])+(.[a-z]+)+ + +Identify 5 unique mistakes in the regular expression by creating test cases that are incorrectly rejected or accepted: + +@yahoo.com - akceptacja bez pierwszego członu e-maila + +netan@y@a@h@o@o.com - akceptacja: nie wyłączamy kropki ze składni regexa więc możemy użyć dowolnej ilości @ lub innych niedozwolonych znaków + +netan@wh4ta.fr!ka - j.w. + +net4n@yahoo.com - odrzucenie: nie możemy używać cyfr w e-mailu (???) + +netan.yahoo@yahoo.com - odrzucenie: nie możemy używać kropek w pierwszym członie e-maila + +netan@localhost - akceptacja (trochę naciągane) - akceptujemy lokalne hostname'y + +netan@yahoo.a - akceptacja (trochę naciągane) - nie weryfikujemy top level domain spośród istniejących (np. pl/de/uk/com itd.) + +--- + +Exercise 16: (2 marks) Develop a regular expression for a binary string that has an even number of 0's: + +((1*(01*0)1*)+|1+) + +--- + +Exercise 17: (2 marks) Develop a regular expression for a binary string that has no consecutive 0's and no consecutive 1's: + +((10)*1?|(01)*0?) + +--- + + + +--- + +Exercise 19: (Bonus 2 marks) Develop a regular expression for a binary string that represents an unsigned value that is divisible by 3: