To learn more about regular expressions in Python, check out:
Wrap Up Finding Substrings With Regex
Okay, so this was a quick overview of working with regular expressions to find substrings with conditions in Python, and you do that with the
re module that you need to import from the standard library. And then we looked at three functions from the
Specifically, those were
re.search(). That gives you back a
Match object of the first regex pattern match in your strings, so starting from the beginning of the string that you’re searching in, the first one that matches is going to get returned.
Then you looked at
.findall(), which gives you a list of strings of all the pattern matches in the whole string that you’ve searched in. And I put a little asterisk (
*) here because like you saw before, if you do have more than one capturing group, then
.findall() doesn’t return a list of strings, but a list of tuples, and the tuples contain the strings representing each of the capturing groups.
01:12 If you want to learn more about regular expressions in Python, then we do have a couple of resources on the site. There’s a video course and a text about Regular Expressions and Building Regexes in Python. There’s another, part-two regular expressions tutorial as well.
Become a Member to join the conversation.