# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(&)('.$Key.')([^0-9a-zA-Z_])"
test_str = ("<?php \n"
"// Сравниваем Куки Ñ Ð´Ð°Ð½Ð½Ñ‹Ð¼Ð¸\n"
"if ($_COOKIE['login'] == $admin_login AND $_COOKIE['password'] == md5($admin_pass))\n"
"{\n"
"If (isset($_POST['submit'])){\n"
" $date=explode(\".\", date(\"d.m.Y\"));\n"
"switch ($date[1]){\n"
"case 1: $m='ÑнварÑ'; break;\n"
"case 2: $m='февралÑ'; break;\n"
"case 3: $m='марта'; break;\n"
"case 4: $m='апрелÑ'; break;\n"
"case 5: $m='маÑ'; break;\n"
"case 6: $m='июнÑ'; break;\n"
"case 7: $m='июлÑ'; break;\n"
"case 8: $m='авгуÑта'; break;\n"
"case 9: $m='ÑентÑбрÑ'; break;\n"
"case 10: $m='октÑбрÑ'; break;\n"
"case 11: $m='ноÑбрÑ'; break;\n"
"case 12: $m='декабрÑ'; break;\n"
"}\n"
"$createdata = $date[0].' '.$m.', '.$date[2];\n"
" $useradd = 'Admin'; \n"
" $name = $_POST['amess'];\n"
" $useradd = $_POST['useradd'];\n"
" $text = $_POST['mess'];\n"
" $textkrat = $_POST['opisan'];\n"
" $title = $_POST['title'];\n"
" $description = $_POST['description'];\n"
" $keyword = $_POST['keywords'];\n"
" \n"
" $url = $_POST['amessurl'];\n"
" $tegs = $_POST['tegs'];\n"
"?>")
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