Are you trying to search for or clean up certain segments of text in your documents or data files, but it's taking hours to search and replace, because you have to type many slightly different versions of the keywords you're searching for? Perhaps you need to replace month names with just the first three letters, but you don't want to do this 12 times (once for each month), for lowercase, capitalized first letter, and all-caps versions? Or perhaps you only want to do so when the month name is part of a full date expression, e.g. "March 2, 2001", but not in the phrase "they're planning a march on Wall Street."
Introducing regular expressions: special text strings that allow you to define text patterns in flexible and complex ways. Regular expressions are useful in many applications. They can be used to search for and replace text in a simple text editor, or in your datasets in Python or R.
In this workshop, we'll learn how to build regular expressions using special characters, sets or quantities of characters, the absence of certain characters, this-or-that alternatives, and other options. Then we'll briefly demonstrate how to use these expressions in Python, to get you familiar with the package you'll use in your own programming.
Prior knowledge: Although the workshop can be completed without a background in Python, familiarity with Python is strongly encouraged. We use Python as a way of demonstrating what regular expressions can do, but the core substance is on regular expressions, which are present in all modern programming languages and text editors. A level of Python of our FUN!damentals series is encouraged.
Technology requirements:
- Laptop required.
- WindowsWindows machines please download and go through the installer for GitBash. Then download Anaconda. Click the download for Python 3.6. Run the installer.
- Mac Mac machines please download Anaconda. Click the download for Python 3.6 and the Graphical Installer. Run the installer.
- Please also download the Github repository with the materials for this workshop. Click here, click on the green button labeled "Clone or download", and select "Download ZIP." Then unzip the downloaded file and place the folder on your desktop.