8 Regular Expressions in Python

8.1 Getting your python environment working

To experiment with regular expressions in python, you will need access to python 3 and the requests module. If you don’t already have python running on your machine, here are some options.

8.1.1 repl.it

This python-in-a-browser seems able to do what we need (based on minimal testing)

https://repl.it/languages/python3

8.1.2 Thonny

If you prefer to install a simple versions of python locally, try Thonny.

  1. Download and install Thonny from https://thonny.org/.

  2. Make sure the requests module is available.

    In Thonny, you can install packages from the tools > manage packages menu:

    Then search PyPI for requests and hit install.

8.1.3 Testing your python setup

If you can run the following and get the same output, you should be OK.

import re
import requests
# Download St. Augustine’s confessions from CCEL and print it
url = 'https://www.ccel.org/ccel/augustine/confess.txt'
r = requests.get(url)
book = r.text
print(len(book))
## 708873
print(book[1015:1120])
##        Everywhere God wholly filleth all things, but neither heaven nor
##        Earth containeth him.
## 
foo = re.compile("aug")
print(foo.search(book))
## <_sre.SRE_Match object; span=(4314, 4317), match='aug'>