# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(^\w*[ а-яА-Яa-zA-Z:,\/]*\\?$)|^\\*[\w .:]*\\*\/?(.*)"
test_str = ("\\\\\\\\atxr2.atxr.ru\\\\_resource_test_001001\\\\_dir1\n"
"c:\\\\_resource_test_001001\\\\_dir1\n"
"\\\\atxr2.atxr.ru\\_resource_test_001001\\_dir1\n"
"D:\\\n"
"_dir1\n"
"\\\\atxr2.atxr.ru\\_resource_test_001004\n"
"Локальное имя\n"
"_resource_test_001004\n"
"Разделяемое устройство\n"
"atxr.ru/Users/Administrator\n"
"atxr2.atxr.ru/_resource_test_001004\n"
"atxr2.atxr.ru\\_resource_test_001004\n"
"Удаление,Смена владельца документа,Смена владельца,Удаление документа,Просмотр разрешений документа,Просмотр разрешений,Управление документами,Управление принтером,Просмотр документов,Печать,Установка разрешений документа,Установка разрешений\n"
"Подразделение Active Directory\n"
"atxr.ru/_resource_test_0011015/_resource2_test_0011015\n"
"atxr.ru/_resource_test_0011015/_user1_test_0011015\n"
"Содержание папки/Чтение данных,Чтение дополнительных атрибутов,Обзор папок/Выполнение файлов,Чтение атрибутов,Чтение разрешений\n\n"
"(^[\\w а-яА-Я:]*\\\\?$)|(^[A-Z]{1}:\\\\$)|^[\\\\a-zA-Z0-9.-:]*[\\\\\\/](.*)\n"
"(^[\\w а-яА-Я:]*\\\\?$)|^[\\\\a-zA-Z. :0-9-]*\\\\\\/?(.*)\n"
"(^\\w*[ а-яА-Яa-zA-Z:,\\/]*\\\\?$)|^\\\\*[\\w .:]*\\\\*\\/?(.*)")
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