# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\"year\"\:(\d{4})\,"
test_str = "{\"total_pages\":1,\"total_count\":3,\"per_page\":60,\"page\":1,\"data\":[{\"id\":\"524414\",\"type\":\"subtitle\",\"attributes\":{\"subtitle_id\":\"524414\",\"language\":\"ro\",\"download_count\":1421,\"new_download_count\":1,\"hearing_impaired\":false,\"hd\":false,\"fps\":25.0,\"votes\":0,\"ratings\":0.0,\"from_trusted\":false,\"foreign_parts_only\":false,\"upload_date\":\"2010-03-07T08:17:40Z\",\"ai_translated\":false,\"machine_translated\":false,\"release\":\"Casino Royale - oo7\",\"comments\":\"AUTOLOAD AUTOUPLOAD\",\"legacy_subtitle_id\":3650579,\"uploader\":{\"uploader_id\":3282,\"name\":\"os-auto\",\"rank\":\"Application Developers\"},\"feature_details\":{\"feature_id\":518630,\"feature_type\":\"Movie\",\"year\":1967,\"title\":\"Casino Royale\",\"movie_name\":\"1967 - Casino Royale\",\"imdb_id\":61452,\"tmdb_id\":12208},\"url\":\"https://www.opensubtitles.com/ro/subtitles/legacy/3650579\",\"related_links\":{\"label\":\"All subtitles for Casino Royale\",\"url\":\"https://www.opensubtitles.com/ro/movies/1967-casino-royale\",\"img_url\":\"https://s9.osdb.link/features/0/3/6/518630.jpg\"},\"files\":[{\"file_id\":579397,\"cd_number\":1,\"file_name\":\"Casino Royale - oo7.sub\"}],\"moviehash_match\":true}},{\"id\":\"522774\",\"type\":\"subtitle\",\"attributes\":{\"subtitle_id\":\"522774\",\"language\":\"es\",\"download_count\":1003,\"new_download_count\":1,\"hearing_impaired\":false,\"hd\":false,\"fps\":25.0,\"votes\":2,\"ratings\":9.5,\"from_trusted\":false,\"foreign_parts_only\":false,\"upload_date\":\"2003-12-18T23:00:00Z\",\"ai_translated\":false,\"machine_translated\":false,\"release\":\"Casino Royale (1967)\",\"comments\":null,\"legacy_subtitle_id\":59217,\"uploader\":{\"uploader_id\":8092,\"name\":\"ShooCat (a)\",\"rank\":\"bronze member\"},\"feature_details\":{\"feature_id\":518630,\"feature_type\":\"Movie\",\"year\":1967,\"title\":\"Casino Royale\",\"movie_name\":\"1967 - Casino Royale\",\"imdb_id\":61452,\"tmdb_id\":12208},\"url\":\"https://www.opensubtitles.com/es/subtitles/legacy/59217\",\"related_links\":{\"label\":\"All subtitles for Casino Royale\",\"url\":\"https://www.opensubtitles.com/es/movies/1967-casino-royale\",\"img_url\":\"https://s9.osdb.link/features/0/3/6/518630.jpg\"},\"files\":[{\"file_id\":577519,\"cd_number\":1,\"file_name\":\"Casino Royale (SPA).srt\"}],\"moviehash_match\":true}},{\"id\":\"525409\",\"type\":\"subtitle\",\"attributes\":{\"subtitle_id\":\"525409\",\"language\":\"es\",\"download_count\":432,\"new_download_count\":2,\"hearing_impaired\":false,\"hd\":false,\"fps\":25.0,\"votes\":0,\"ratings\":0.0,\"from_trusted\":false,\"foreign_parts_only\":false,\"upload_date\":\"2014-05-04T22:40:02Z\",\"ai_translated\":false,\"machine_translated\":false,\"release\":\"James Bond - 007 - Casino Royale -1967\",\"comments\":\"\",\"legacy_subtitle_id\":5657430,\"uploader\":{\"uploader_id\":3282,\"name\":\"os-auto\",\"rank\":\"Application Developers\"},\"feature_details\":{\"feature_id\":518630,\"feature_type\":\"Movie\",\"year\":1967,\"title\":\"Casino Royale\",\"movie_name\":\"1967 - Casino Royale\",\"imdb_id\":61452,\"tmdb_id\":12208},\"url\":\"https://www.opensubtitles.com/es/subtitles/legacy/5657430\",\"related_links\":{\"label\":\"All subtitles for Casino Royale\",\"url\":\"https://www.opensubtitles.com/es/movies/1967-casino-royale\",\"img_url\":\"https://s9.osdb.link/features/0/3/6/518630.jpg\"},\"files\":[{\"file_id\":580507,\"cd_number\":1,\"file_name\":\"James Bond - 007 - Casino Royale -1967-spa.srt\"}],\"moviehash_match\":true}}]}"
matches = re.search(regex, test_str)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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