Chapters
Python114 chapters

Exercises

RegEx

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Find every run of digits in the text.

Python
import re

text = "call 0176 1234567"
# print the list of digit runs
Exercise 2

search returns None here. Print 'nothing matched' rather than crashing.

Python
import re

found = re.search(r"\d+", "no digits here")
print(found.group())
Exercise 3

The greedy pattern swallows the whole string. Make it match each tag separately.

Python
import re

html = "<b>bold</b>"
print(re.findall(r"<.+>", html))