# Import regex
import re
# Create some data
text = 'A flock of 120 quick brown foxes jumped over 30 lazy brown, bears.'
re.findall('^A', text)
['A']
re.findall('bears.$', text)
['bears.']
re.findall('f..es', text)
['foxes']
# Find all vowels
re.findall('[aeiou]', text)
['u', 'i', 'o', 'o', 'e', 'u', 'e', 'o', 'e', 'a', 'o', 'e', 'a']
# Find all characters that are not lower-case vowels
re.findall('[^aeiou]', text)
['A', ' ', '1', '2', '0', ' ', 'q', 'c', 'k', ' ', 'b', 'r', 'w', 'n', ' ', 'f', 'x', 's', ' ', 'j', 'm', 'p', 'd', ' ', 'v', 'r', ' ', '3', '0', ' ', 'l', 'z', 'y', ' ', 'b', 'r', 'w', 'n', ',', ' ', 'b', 'r', 's', '.']
re.findall('a|A', text)
['A', 'a', 'a']
# Find any instance of 'fox'
re.findall('(foxes)', text)
['foxes']
# Break up string into five character blocks
re.findall('\w\w\w\w\w', text)
['quick', 'brown', 'foxes', 'jumpe', 'brown', 'bears']
re.findall('\W\W', text)
[', ']
re.findall('\s', text)
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
re.findall('\S\S', text)
['12', 'qu', 'ic', 'br', 'ow', 'fo', 'xe', 'ju', 'mp', 'ed', 'ov', 'er', '30', 'la', 'zy', 'br', 'ow', 'n,', 'be', 'ar', 's.']
re.findall('\d\d\d', text)
['120']
re.findall('\D\D\D\D\D', text)
[' quic', 'k bro', 'wn fo', 'xes j', 'umped', ' over', ' lazy', ' brow', 'n, be']
re.findall('\AA', text)
['A']
re.findall('bears.\Z', text)
['bears.']
re.findall('\.\z', text)
[]
re.findall('\b[foxes]', text)
[]
re.findall('\n', text)
[]
re.findall('[Ff]oxes', 'foxes Foxes Doxes')
['foxes', 'Foxes']
re.findall('[Ff]oxes', 'foxes Foxes Doxes')
re.findall('[a-z]', 'foxes Foxes')
['f', 'o', 'x', 'e', 's', 'o', 'x', 'e', 's']
re.findall('[A-Z]', 'foxes Foxes')
['F']
re.findall('[a-zA-Z0-9]', 'foxes Foxes')
['f', 'o', 'x', 'e', 's', 'F', 'o', 'x', 'e', 's']
re.findall('[^aeiou]', 'foxes Foxes')
['f', 'x', 's', ' ', 'F', 'x', 's']
re.findall('[^0-9]', 'foxes Foxes')
['f', 'o', 'x', 'e', 's', ' ', 'F', 'o', 'x', 'e', 's']
re.findall('foxes?', 'foxes Foxes')
['foxes']
re.findall('ox*', 'foxes Foxes')
['ox', 'ox']
re.findall('ox+', 'foxes Foxes')
['ox', 'ox']
re.findall('\d{3}', text)
['120']
re.findall('\d{2,}', text)
['120', '30']
re.findall('\d{2,3}', text)
['120', '30']
re.findall('^A', text)
['A']
re.findall('bears.$', text)
['bears.']
re.findall('\AA', text)
['A']
re.findall('bears.\Z', text)
['bears.']
re.findall('bears(?=.)', text)
['bears']
re.findall('foxes(?!!)', 'foxes foxes!')
['foxes']
re.findall('foxes|foxes!', 'foxes foxes!')
['foxes', 'foxes']
re.findall('fox(es!)', 'foxes foxes!')
['es!']
re.findall('foxes(!)', 'foxes foxes!')
['!']