







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
An introduction to regular expressions, a powerful tool for specifying and matching patterns in strings. Regular expressions are used to define regular languages, which can be matched against strings using Python's re module. the basics of regular expression matching using the match() and search() functions, as well as the use of metacharacters, repetition, character classes, and capture groups. It also includes examples of using these techniques to extract specific information from strings.
What you will learn
Typology: Schemes and Mind Maps
1 / 13
This page cannot be seen from the preview
Don't miss anything!
re.match(r'foo', 'foobar') <_sre.SRE_Match object; span=(0, 3), match='foo'> re.match(r'oo', 'foobar')
re.match(r'oo', 'foobar') re.search(r'oo', 'foobar') <_sre.SRE_Match object; span=(1, 3), match='oo'>
re.findall(r'na', 'nana nana nana nana Batman!') ['na', 'na', 'na', 'na', 'na', 'na', 'na', 'na']
m = re.match(r'foo', 'foobar') if m: ... print('Match found: ' + m.group()) ... Match found: oo
re.findall(r'a.a*', 'abra abra cadabra') ['ab', 'a a', 'a ', 'ada']
re.findall(r'a.+a', 'abra abra cadabra') ['abra abra cadabra']
re.findall(r'a.+?a', 'abra abra cadabra') ['abra', 'abra', 'ada']
re.findall(r'ab?a', 'aba anna abba aa') ['aba', 'aa']
re.findall(r'ab{2}a', 'aba anna abba abbba') ['abba']
re.findall(r'[rmpl]ain', 'the rain in spain falls mainly in the plain') ['rain', 'pain', 'main', 'lain']
re.findall(r'[0-9]+', '500 Tech Parkway, Atlanta, GA 30332') [' 500 ', ' 30332 ']
re.findall(r'rain|plain', 'the rain in spain falls mainly in the plain') ['rain', 'plain']
activities = ''' ...
...
''' re.findall(r'- eat
...- sleep
...- code
...(.+) ', activities) ['eat', 'sleep', 'code']