Created
January 27, 2017 08:52
-
-
Save codelingoblog/0b2604ff0dd0bb25949393a4dac5a507 to your computer and use it in GitHub Desktop.
Regex Part 1 - Search for years in the given text
This file contains 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 | |
# 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