Created
November 3, 2014 22:52
-
-
Save ethanwhite/93625ddff3a760e1934e to your computer and use it in GitHub Desktop.
regex example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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