A Simple Example

Let's say that you're looking for a job in the newspaper and you've decided to narrow your focus to ads that say, “Money is no object.” This is the pattern you're searching for, and of course you're looking in the employment section, which is the group of characters you're searching in. You don't care where you find your pattern, only that it's there.

If you were writing a Python program to help you find a job, it would start out looking like this:

>>> from re import *
mino = compile("money is no object");

for ad in classifieds:
        if(mino.search(ad)):
        print ad;

Let's work through this example interactively.

Import the re module.

>>> from re import *

Import class re.

 >>> classifieds = ["School Teacher; salary $20,000.","Engineer; ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.