Friday, January 16, 2015

Overview

In this post, I will be talking about python’s regular expression module called re. I’ll mainly give examples. More information can be found here here.

Examples

1
2
3
4
5
6
7
8
9
10
11
12
13
import re

# look for 'thing' in the string 'that thing'
match = re.search(r'thing', 'that thing')
# match.group() == 'thing'

# look for 'thig' in the string 'that thing'
match = re.search(r'thig', 'that thing')
# match == None

# . = any character except \n
match = re.search(r'..d+', 'abcdd')
# match.group() == 'bcdd' 

Random Posts