CS 1110 Lecture Notes - Lecture 1: Regular Expression

34 views4 pages

Document Summary

Finder. findall(text) >> return a list of str or a list of tuple of str: not the best one to use. M = finder. search(text) >> returns nothing [ ] if not found. Find. finditer(text) >> return a collection of match objects: almost always put in a for loop; finds all. Print(m. strart(), m. edu(), m. group()) >> returns start index, end index, and string of what was matched. Print(m. start(), m. end(), m. group() >> because none won"t work. If your code should be producing something and isn"t, likely you wrote regular expression in way that it can"t find any of them. Findall( ) will return a tuple of all that are matched if there are any parenthesis. Findall will sometimes give tuples, and sometimes give strings. Using regex to find certain words following articles: ^^ if you add a pair of parenthesis around the second piece, you will match not only the article, but the word following it. After_article. append(m. group(2)) >> this appends what follows the expression.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents