Last active
December 18, 2015 07:39
-
-
Save simonwhitaker/5748515 to your computer and use it in GitHub Desktop.
A port of https://gist.github.com/simonwhitaker/5748487 to Python
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 | |
tweet = "Currently chilling out at W1B 2EL, then on to WC2E 8HA or maybe even L1 8JF! :-)" | |
# Here's a simple regex that tries to recognise postcode-like strings. | |
# See http://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Validation | |
# for the rules on how UK postcodes are formatted. | |
postcode_regex = '[A-Z]{1,2}[0-9][0-9A-Z]?\s?[0-9][A-Z]{2}' | |
postcodes = re.findall(postcode_regex, tweet) | |
print postcodes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment