Skip to content

Instantly share code, notes, and snippets.

@codelingoblog
Created January 27, 2017 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codelingoblog/0b2604ff0dd0bb25949393a4dac5a507 to your computer and use it in GitHub Desktop.
Save codelingoblog/0b2604ff0dd0bb25949393a4dac5a507 to your computer and use it in GitHub Desktop.
Regex Part 1 - Search for years in the given text
import re
# regex to search for years
regex = "\d{4}"
text = "In 1828, Anyos Jedlik, a Hungarian who invented an early type of electric motor, created a tiny model car powered by his new motor. In 1838, Scotsman Robert Davidson built an electric locomotive that attained a speed of 4 miles per hour (6 km/h)."
print(re.findall(regex, text))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment