Python Tutorial 28
Python Tutorial 28
I continue teaching about Regular Expressions. We’ll learn how to match any character,
whitespace, numbers, one or more items, and we’ll learn how to tell if an email address is
legitimate or not.
We saw that . matches any character, but what if we want to match a period. Backslash the
period. You do the same with [, ] and others.
CODE
Matching Whitespace
CODE
print(rand_str)
# Remove newlines
regex = re.compile("\n")
print(rand_str)
# \b : Backspace
# \f : Form Feed
# \r : Carriage Return
# \t : Tab
# \v : Vertical Tab
CODE
randStr = "12345"
CODE
if re.search("\d{5}", "12345"):
CODE
ph_num = "412-555-1212"
if re.search("\w{3}-\w{3}-\w{4}", ph_num):
if re.search("\w{2,20}", "Ultraman"):
Matching WhiteSpace
CODE
Create a Regex that matches email addresses from a list. Translate the following rules into a
Regex.
2. An @ symbol
4. A period
Solution
emailList)))
In the next video I’ll continue down the path of turning you into a Regex Expert!