Presentation is loading. Please wait.

Presentation is loading. Please wait.

i206: Lecture 19: Regular Expressions, cont.

Similar presentations


Presentation on theme: "i206: Lecture 19: Regular Expressions, cont."— Presentation transcript:

1 i206: Lecture 19: Regular Expressions, cont.
Marti Hearst Spring 2012

2 Regex for Dollars No commas With commas With or without commas
\$[0-9]+(\.[0-9][0-9])? With commas \$[0-9][0-9]?[0-9]?(,[0-9][0-9][0-9])*(\.[0-9][0-9])? With or without commas \$[0-9][0-9]?[0-9]?((,[0-9][0-9][0-9])*| [0-9]*) (\.[0-9][0-9])?

3 Using Regex’s Two basic operations that regular expressions are used for: searching and matching. Searching: moving through a string to locate a sub-string that matches a given pattern, Matching: testing a string to see if it conforms to a pattern. After matching you might want to substitute in alternative strings, or split up the strings.

4 Regex in Python Python documentation on regular expressions
import re result = re.search(pattern, string) result = re.findall(pattern, string) result = re.match(pattern, string) Python documentation on regular expressions Some useful flags like IGNORECASE, MULTILINE, DOTALL, VERBOSE A nice tutorial:

5 Verbose Regex’s (allows for comments and multi-line expressions)
On input of: XXX,36346, , -1


Download ppt "i206: Lecture 19: Regular Expressions, cont."

Similar presentations


Ads by Google