Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions 07/01_uzivatelske_jmeno.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import re

rv = re.compile(r"[a-z]{1,8}")

while True:
uzivatelske_jmeno = input("Uživatelské jméno: ")

if rv.fullmatch(uzivatelske_jmeno):
print("Uživatelské jméno je v pořádku.")
break
else:
print("Nesprávně zadané uživatelské jméno!")
10 changes: 10 additions & 0 deletions 07/02_email_s_teckou.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import re

regularni_vyraz = re.compile(r"\w+\.?\w+@\w+\.cz")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tady ten regexp bude vyžadovat minimálně 2 znaky před zavináčem (mezi kterými může nebo nemusí být tečka). Jinak super.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZelenyMartin
Opravený regulární výraz: r"(\w+.)?\w+@\w+.cz"
Takhle je to OK?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jo. V pohodě.


email = input("Zadej e-mail: ")
hledani = regularni_vyraz.fullmatch(email)
if hledani:
print("E-mail je v pořádku!")
else:
print("Nesprávný e-mail!")
15 changes: 15 additions & 0 deletions 07/03_zaznamy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import re

zaznamy = """
searchNumber: pavca.czechitas action: search phone number of user dita
user: pavca action: send sms to phone number +420728123456
user: jirka: action: send 2 sms to phone number +420734123456
"""

rv = re.compile(r"\+420\d{9}")

for tel in rv.findall(zaznamy):
print(tel)

upravene_zaznamy = rv.sub("X" *12, zaznamy)
print(upravene_zaznamy)
15 changes: 15 additions & 0 deletions 07/04_adresy_stranek.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import re

email_s_radami = """
Ahoj,
posílám ti pár tipů, kam se podívat. https://realpython.com nabízí spoustu článků i kurzů.
http://docs.python.org nabízí tutoriál i rozsáhlou dokumentaci.
http://www.learnpython.org nabízí hezky strukturovaný kurz pro začátečníky, rozebírá ale i nějaká pokročilejší témata.
https://www.pluralsight.com je placený web, který ale kvalitou kurzů víceméně nemá konkurenci.
Určitě ale sleduj i web https://www.czechitas.cz a přihlašuj se na naše kurzy!
"""

rv = re.compile(r"https?://\w*\.?\w+\.[a-z]{2,3}")

adresy = rv.findall(email_s_radami)
print(adresy)
13 changes: 13 additions & 0 deletions 07/05_ip_adresy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import re

ip_adresa = input("Zadejte IP adresu: ")

rv = re.compile(r"([1-2]?\d?\d\.){3}[1-2]?\d?\d")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rv = re.compile(r"([1-2]?\d?\d\.){3}[1-2]?\d?\d")
rv = re.compile(r"([12]?\d?\d\.){3}[12]?\d?\d")

Mělo byt fungovat i takto. Celkově vynikající!


platna_ip_adresa = rv.fullmatch(ip_adresa)

if platna_ip_adresa:
print("Zadaná IP adresa je v pořádku.")
else:
print("Zadaná IP adresa není platná.")