Learning Patterns Through Examples

Really good regular expressions—the type used in a production software environment—can get very long and complicated. Since you’re learning, we’ll keep our regular expressions simple for now. As such, this chapter is not meant to be a compete tutorial on regular expressions, but it should be sufficient to help you grasp the concept so you can do your own experimentation and then learn on your own. Later, you’ll learn how to use your new skills to do something more applicable to the real world.

Parsing Numbers

To get started, you can use regular expressions to easily parse all the numbers from a string, as shown in Example 5-5.

Example 5-5. Parsing numbers with regular expressions

$subject_string = "There are 129 ...

Get Webbots, Spiders, and Screen Scrapers, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.