# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"\\\"(title|url)\\\": \\\"[^\"]*\\\""
test_str = ("1. Есть строки в текстовом файле: \"title\": \"разный текст\"\n"
"Найти всё в этом файле.\n"
"2. Есть строки в текстовом файле:\n"
"\"url\": \"разный текст\"\n"
"Найти всё в этом файле.\n\n"
"3. Есть всё в общей строке в текстовом файле:\n"
"\"title\": \"разный текст\", \"url\": \"разный текст\"\n\n"
"[{\"hostName\": \"youtube\", \"name\": \"Rock & Roll 50's Mix\", \"type\": \"VIDEO\", \"iconimage\": \"https://i.ytimg.com/vi/gLzn8nDVSo8/hq720.jpg?sqp=-...\", \"resolver\": \"youtube\", \"data\": \"{\\\"category\\\": \\\"video\\\", \\\"name\\\": \\\"category\\\", \\\"title\\\": \\\"Rock & Roll 50's Mix\\\", \\\"url\\\": \\\"http://www.youtube.com/watch?v=gLzn8nDVSo8\\\", \\\"time\\\": \\\"9 \\\\u043b\\\\u0435\\\\u0442 \\\\u043d\\\\u0430\\\\u0437\\\\u0430\\\\u0434\\\", \\\"desc\\\": \\\"Duration: 11:38 | 71\\\\u00a0528\\\\u00a0835 \\\\u043f\\\\u0440\\\\u043e\\\\u0441\\\\u043c\\\\u043e\\\\u0442\\\\u0440\\\\u043e\\\\u0432 | 9 \\\\u043b\\\\u0435\\\\u0442 \\\\u043d\\\\u0430\\\\u0437\\\\u0430\\\\u0434\\\\ndjdirtybeat\\\\nPLEASE LIKE MY FACEBOOK PAGE, Download Here https://soundcloud.com/mauricio-villegas-12\\\\u00a0...\\\", \\\"type\\\": \\\"video\\\", \\\"icon\\\": \\\"https://i.ytimg.com/vi/gLzn8nDVSo8/hq720.jpg?sqp=-...\"}\", \"description\": \"Duration: 11:38 | 71\\u00a0528\\u00a0835 \\u043f\\u0440\\u043e\\u0441\\u043c\\u043e\\u0442\\u0440\\u043e\\u0432 | 9 \\u043b\\u0435\\u0442 \\u043d\\u0430\\u0437\\u0430\\u0434\\ndjdirtybeat\\nPLEASE LIKE MY FACEBOOK PAGE, Download Here https://soundcloud.com/mauricio-villegas-12\\u00a0...\"}, {\"hostName\": \"youtube\", \"name\": \"Free - All Right Now\", \"type\": \"VIDEO\", \"iconimage\": \"https://i.ytimg.com/vi/YExuLkIaQ7U/hq720.jpg?sqp=-...\", \"resolver\": \"youtube\", \"data\": \"{\\\"category\\\": \\\"video\\\", \\\"name\\\": \\\"category\\\", \\\"title\\\": \\\"Free - All Right Now\\\", \\\"url\\\": \\\"http://www.youtube.com/watch?v=YExuLkIaQ7U\\\", \\\"time\\\": \\\"11")
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