Skip to content

Latest commit

 

History

History
43 lines (25 loc) · 1.42 KB

File metadata and controls

43 lines (25 loc) · 1.42 KB

Introduction to Regular Expressions

Author: Anne Sonnenschein Created: 11/13/2015

This tutorial is designed to give a brief introduction to regular expressions.

Overview

Regular expressions (or regex) are a language for search and replace. They allow search for wild-cards: characters that can match more than one string. This can be especially useful for text editing, or converting large files from one format to another. Regular expressions are enabled in some text editors, and many programming languages (notably Python and Perl). In Unix they are implemented in tools such as grep and sed. The syntax is generally common across platforms.

In this tutorial, you will learn syntax for simple regular expressions, and how to implement them in text editors, python and perl.

Regex using text editors

For this part of the activity you will need a text editor with regular expressions enabled. For the exercise at the end, you will need either Python or Perl.

TextWrangler (Mac) http://www.barebones.com/products/textwrangler/download.html

Notepad++ (Windows) https://notepad-plus-plus.org/download/v6.8.6.html

Text editor exercises

Regex using Python

# python code
import this

Regex using Perl

Programming exercises

XKCD link ** from https://xkcd.com/208/

References

Haddock and Dunn, 2011. Practical Computing for Biologists, chapter 2