Module 2 video notes.docx - Using Python to Access Web...

This preview shows page 1 - 7 out of 24 pages.

The preview shows page 5 - 7 out of 24 pages.
Using Python to Access Web Date:Video 11.1Two: Regular Expressions: Part 1Chapter 11:So welcome to Chapter 11. Chapter 11’s kind of a fun chapter because youdon’t really need to now regular expressions. And so, if you just want to skipahead, or maybe do the assignment or whatever, but this is kind of fun,regular expressions are a neat little thing. They are real old concept, they’rekind of an ancient notation and having to do with the study of languages, notreally exactly computer programming languages, but languages, andgrammars, and what is in a language and what is not in the language, andregular expression is a form of a language, and meaning it’s a way to saythat a set of strings match or don’t match a regular expression.Regular Expressions- In computing, a regular expression, also referredto as “regex” or “regexp”, provides a concise and flexible means formatching strings of text, such as particular characters, words, orpatterns of characters. A regular expression is written in a formallanguage that can be interpreted by a regular expression processor.Understanding Regular Expressions:oVery powerful and quite crypticoFun once you understand themoRegular expressions are a language unto themselvesoA language of“marker characters” – programming withcharactersoIt is kind of an “old school” language – compact1
2
3
4
Video 11.2 Extracting DateSo, now we’re going to talk about extracting data. Up to now, we’ve justbeen playing with the search which gives us back a true or a false dependingon whether it matches or not. But now we’re going to actually pull stuff out.So, we’re going to start by looking at a different regular expression, a newregular expression.The square bracket is kind of weird and that it is one character.So, that is describing in between the square brackets what we mean bya single character.We can have a range in here.Like AEIOU would be vowels.Zero through nine is digit.So, bracket zero dash nine bracket is a single digit.But then, we added a plus to it and that says one or more digits.Now if we put a star that zero or more digits which is kind of weird.But one or more digits, and now we’re going to use a function calledfindall, a function in the regular expression library called findall.5
So, what we’re saying here is the string we’re looking looking through,x, and we’re looking for the pattern, one or more digits.So the it’s going to look and say, “Oh let me see one or more digits.”Oh! That looks good like that one let’s keep looking,. That’s good, andlet’s keep looking and that’s good.So, it may find zero, it may find one, or it may find more than one.So, what it does is it runs all the way through the texts that you’veasked it to look for, checking to see when this matches, and it gives usback a list of the matches.

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 24 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
Regular expression, Bracket, findall findall

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture