#100DaysOfCode in Python Transcripts
Chapter: Days 28-30: Regular Expressions
Lecture: Comparing re.search and re.match
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Now those string operations were pretty basic,
0:03
but usually we need something more advanced.
0:06
Meet, regex.
0:07
The re module has two main methods.
0:11
search and match.
0:14
match, matches from start to end.
0:17
Search can match a substring.
0:19
It's best to use an example.
0:23
I'm using raw strings by the way,
0:25
because then I can just use special characters
0:27
with a single backslash and not having to escape them
0:31
which makes my regexes more readable.
0:34
So again, we have the same awesome I'm doing a 100 days
0:37
of code challenge and let's...
0:41
do a re.search first.
0:43
So I'm going to...
0:46
match a...
0:48
part of that string
0:50
and you can do this as well with just I am in
0:53
but the point is to just show how you would make a regular
0:57
expression and what a match object would look like.
1:02
To contrast that with match,
1:07
this won't work.
1:09
Oops.
1:10
Match takes two arguments.
1:13
So this is None because match ends end to end
1:17
so I am is not the full string.
1:21
So to do a proper match we would be doing,
1:27
start with awesome,
1:30
end with challenge.
1:33
On text and that works.
1:37
And here you see the first part of a pattern
1:40
which is '.' which matches any character,
1:44
zero or more of them
1:47
up until challenge.