# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<=\d{4}\/\d{2}\/\d{2}\/)\w+\-?\w?\/?\w+\/"
test_str = ("\n"
"http://www.nytimes.com/2015/12/27/nyregion/anxiety-aside-new-york-sees-drop-in-crime.html\n"
"http://www.nytimes.com/2015/12/28/us/politics/state-level-brawls-over-medicaid-reflect-wider-war-in-gop.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/28/us/rahm-emanuel-under-siege-in-chicago-shows-contrite-side.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/28/world/middleeast/syria-refugees-alan-aylan-kurdi.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/28/us/politics/how-hillary-clinton-went-undercover-to-examine-race-in-education.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/28/arts/ellsworth-kelly-artist-who-mixed-european-abstraction-into-everyday-life-dies-at-92.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/28/world/middleeast/more-and-more-special-forces-become-obamas-military-answer.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/29/us/tamir-rice-police-shootiing-cleveland.html\n"
"http://www.nytimes.com/2015/12/29/world/middleeast/iraq-ramadi-isis.html\n"
"http://www.nytimes.com/2015/12/29/business/tsa-moves-closer-to-rejecting-some-state-drivers-licenses-for-travel.html\n"
"http://www.nytimes.com/2015/12/29/nyregion/mayor-de-blasio-still-trying-fitfully-to-blow-his-own-horn-better.html\n"
"http://www.nytimes.com/2015/12/29/world/middleeast/iran-hands-over-stockpile-of-enriched-uranium-to-russia.html\n"
"http://www.nytimes.com/2015/12/29/world/asia/comfort-women-south-korea-japan.html\n"
"http://www.nytimes.com/2015/12/29/us/tamir-rice-police-shootiing-cleveland.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/29/world/middleeast/iraq-ramadi-isis.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/29/world/americas/maritime-repo-men-a-last-resort-for-stolen-ships.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/29/technology/universities-race-to-nurture-start-up-founders-of-the-future.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/29/sports/basketball/meadowlark-lemon-harlem-globetrotter-who-played-basketball-and-pranks-with-virtuosity-dies-at-83.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/29/world/asia/comfort-women-south-korea-japan.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/30/business/economy/for-the-wealthiest-private-tax-system-saves-them-billions.html\n"
"http://www.nytimes.com/2015/12/30/us/affluenza-ethan-couch-mexico.html\n"
"http://www.nytimes.com/2015/12/30/us/use-of-affluenza-didnt-begin-with-ethan-couch-case.html\n"
"http://www.nytimes.com/2015/12/30/world/asia/book-says-zhou-enlai-chinese-premier-may-have-been-gay.html\n"
"http://www.nytimes.com/2015/12/30/world/middleeast/isis-ramadi-iraq.html\n"
"http://www.nytimes.com/2015/12/30/world/europe/us-says-airstrikes-killed-militants-tied-to-paris-attacks.html\n"
"http://www.nytimes.com/2015/12/30/business/economy/for-the-wealthiest-private-tax-system-saves-them-billions.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/30/us/politics/ex-ally-donald-trump-now-heaps-scorn-on-bill-clinton.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/30/us/more-police-officers-facing-charges-but-few-see-jail.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/30/nyregion/bratton-rebukes-kelly-for-questioning-new-york-crime-data-shame-on-him.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/30/us/affluenza-ethan-couch-mexico.html?ref=todayspaper\n"
"http://www.nytimes.com/2015/12/31/business/media/bill-cosby-charged-in-sexual-assault-case.html\n"
"http://www.nytimes.com/2015/07/19/arts/bill-cosby-deposition-reveals-calculated-pursuit-of-young-women-using-fame-drugs-and-deceit.html\n"
"http://www.nytimes.com/2015/12/31/world/europe/cellphone-contacts-in-paris-attacks-suggest-foreign-coordination.html\n"
"http://www.nytimes.com/2015/12/31/world/middleeast/muslims-on-twitter-say-they-have-better-things-to-do-than-join-isis.html\n"
"http://www.nytimes.com/2015/12/31/world/europe/belgium-brussels-police-orgy.html")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html