Skip to content

Instantly share code, notes, and snippets.

@ethanwhite
Created November 3, 2014 22:52
Show Gist options
  • Save ethanwhite/93625ddff3a760e1934e to your computer and use it in GitHub Desktop.
Save ethanwhite/93625ddff3a760e1934e to your computer and use it in GitHub Desktop.
regex example
import re
inputfile = open('wikipedia_rodents.txt', 'r')
def get_species(inputstring):
species_regexs = "([A-Z][a-z]+ [a-z]+)"
species_search = re.search(species_re, inputstring)
if species_search:
return species_search.group(1)
results = []
nomatch = []
for line in inputfile:
species = get_species(line)
if species:
results.append(species)
else:
nomatch.append(line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment