{"id":385530,"date":"2024-06-29T06:09:59","date_gmt":"2024-06-29T06:09:59","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=385530"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T06:09:59","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=385530","title":{"rendered":"<span>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 70 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042d\u0442\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0431\u044f\u0437\u0430\u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c\u0443 \u0437\u0430\u0434\u0430\u043d\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0443\u0442\u0438\u043b\u0438\u0442\u044b grep \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 PHP, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438. <\/p>\n<p>\u0421\u0442\u0440\u043e\u043a\u0430 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u043b\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><strong>^<\/strong> &#8212; \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><strong>$<\/strong> &#8212; \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><strong>.<\/strong> &#8212; \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b<\/p>\n<\/li>\n<li>\n<p><strong>*<\/strong> &#8212; 0 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437<\/p>\n<\/li>\n<li>\n<p><strong>?<\/strong> &#8212; 0 \u0438\u043b\u0438 1 \u0440\u0430\u0437<\/p>\n<\/li>\n<li>\n<p><strong>+<\/strong> &#8212; 1 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 &#8216;\\&#8217;, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u043d\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0441\u0442\u0430 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 70 &#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 \u0441\u0443\u0433\u0443\u0431\u043e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0446\u0435\u043b\u044f\u0445, \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0435\u0435 \u043a\u043e\u0434 \u0438 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u0440\u0430\u0437\u0431\u043e\u0440.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<details class=\"spoiler\">\n<summary>grep.php<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\">#!\/bin\/env php &lt;?php  const META_CHAR = 1, LITERAL = 2, META_CHARS = [\"*\", \"?\", \"+\", \".\"];  function is_metachar(string $re, int $i): bool { return in_array($re[$i], META_CHARS) || ($re[$i] === \"^\" &amp;&amp; $i === 0) || ($re[$i] === \"$\" &amp;&amp; $i === (strlen($re) - 1)); }  function tokenize(string $re, int $i = 0): array { $re_tokens = []; $len = strlen($re); while ($i &lt; $len) { if ($re[$i] === '\\\\' &amp;&amp; $i + 1 &lt; $len &amp;&amp; (is_metachar($re, $i + 1) || ($i === 0 &amp;&amp; $re[$i + 1] === \"^\"))) $re_tokens[] = [LITERAL, $re[++$i]]; else $re_tokens[] = [is_metachar($re, $i) ? META_CHAR : LITERAL, $re[$i]]; $i++; } return $re_tokens; }  function match_char(array $re_char, string $str_char): bool { return ($re_char[0] === LITERAL &amp;&amp; $re_char[1] === $str_char) || ($re_char[0] === META_CHAR &amp;&amp; $re_char[1] === \".\"); }  function match_metachar(array $tokens, int $pos, string $char): bool { return isset($tokens[$pos]) &amp;&amp; $tokens[$pos][0] === META_CHAR &amp;&amp; $tokens[$pos][1] === $char; }  function is_end($data, int $pos): bool { return !isset($data[$pos]); }  function re_match(array $re_tokens, string $str, int $str_pos = 0): bool { if (match_metachar($re_tokens, 0, \"^\")) return match_from_pos($re_tokens, 1, $str, 0);  $match = false; while (!$match &amp;&amp; !is_end($str, $str_pos)) $match = match_from_pos($re_tokens, 0, $str, $str_pos++); return $match; }  function match_from_pos(array $re_tokens, int $re_pos, string $str, int $str_pos): bool { if (is_end($re_tokens, $re_pos)) return true;  if (match_metachar($re_tokens, $re_pos, \"$\")) return is_end($str, $str_pos);  if (match_metachar($re_tokens, $re_pos + 1, \"*\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (!is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"+\")) return match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; (match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1) || match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"?\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1));  return !is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 1, $str, $str_pos + 1); }  function grep($file, array $re_tokens, string $fname = \"\"): void { $line = 0; while (($str = fgets($file)) !== false &amp;&amp; ++$line) if (re_match($re_tokens, $str = rtrim($str, \"\\r\\n\"))) echo ($fname ? \"{$fname}:\" : \"\") . \"{$line}:{$str}\\n\"; }  if ($argc &lt; 2) exit(\"Usage: {$argv[0]} pattern [file1 file2 ...]\\n\");  $re_tokens = tokenize($argv[1]);  if ($argc == 2) { grep(STDIN, $re_tokens); } else { for ($i = 2; $i &lt; $argc; $i++) { if (is_dir($argv[$i])) { fwrite(STDERR, \"{$argv[0]}: {$argv[$i]} : Is a directory\\n\"); continue; } $f = @fopen($argv[$i], \"r\"); if ($f === false) { fwrite(STDERR, \"Cannot open file: {$argv[$i]}\\n\"); continue; } grep($f, $re_tokens, $argc > 3 ? $argv[$i] : \"\"); fclose($f); } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b: <\/p>\n<pre><code class=\"bash\">.\/grep.php '^funct+is?.*pos.*$.*bool$' grep.php 30:function match_metachar(array $tokens, int $pos, string $char): bool 51:function match_from_pos(array $re_tokens, int $re_pos, string $str, int $str_pos): bool<\/code><\/pre>\n<p>\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0440\u0430\u0437\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>tokenize<\/strong>:<\/p>\n<pre><code class=\"php\">&lt;?php  const META_CHAR = 1, LITERAL = 2, META_CHARS = [\"*\", \"?\", \"+\", \".\"];  function is_metachar(string $re, int $i): bool { return in_array($re[$i], META_CHARS) || ($re[$i] === \"^\" &amp;&amp; $i === 0) || ($re[$i] === \"$\" &amp;&amp; $i === (strlen($re) - 1)); }  function tokenize(string $re, int $i = 0): array { $re_tokens = []; $len = strlen($re); while ($i &lt; $len) { if ($re[$i] === '\\\\' &amp;&amp; $i + 1 &lt; $len &amp;&amp; (is_metachar($re, $i + 1) || ($i === 0 &amp;&amp; $re[$i + 1] === \"^\"))) $re_tokens[] = [LITERAL, $re[++$i]]; else $re_tokens[] = [is_metachar($re, $i) ? META_CHAR : LITERAL, $re[$i]]; $i++; } return $re_tokens; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u0442 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0442\u0438\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d (\u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c \u0441\u0442\u043e\u0438\u0442 \u0441\u043b\u0435\u0448 &#171;<strong>\\<\/strong>&#171;), \u0442\u043e \u043e\u043d \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u043c. \u0422\u0430\u043a \u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <strong>^<\/strong> \u0438 <strong>$<\/strong> \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438 \u043a\u043e\u043d\u0446\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<pre><code class=\"php\">&lt;?php  function match_char(array $re_char, string $str_char): bool { return ($re_char[0] === LITERAL &amp;&amp; $re_char[1] === $str_char) || ($re_char[0] === META_CHAR &amp;&amp; $re_char[1] === \".\"); }  function match_metachar(array $tokens, int $pos, string $char): bool { return isset($tokens[$pos]) &amp;&amp; $tokens[$pos][0] === META_CHAR &amp;&amp; $tokens[$pos][1] === $char; }  function is_end($data, int $pos): bool { return !isset($data[$pos]); }  function re_match(array $re_tokens, string $str, int $str_pos = 0): bool { if (match_metachar($re_tokens, 0, \"^\")) return match_from_pos($re_tokens, 1, $str, 0);  $match = false; while (!$match &amp;&amp; !is_end($str, $str_pos)) $match = match_from_pos($re_tokens, 0, $str, $str_pos++); return $match; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <strong>re_match<\/strong> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>tokenize<\/strong> \u0438 \u0441\u0442\u0440\u043e\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u044e, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0). \u0415\u0441\u043b\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u0430 &#171;<strong>^<\/strong>&#171;, \u0442\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0433\u043e \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438.\u00a0\u0412 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0432 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0441\u0434\u0432\u0438\u0433\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043a\u043e\u043d\u0435\u0446).<\/p>\n<pre><code class=\"php\">&lt;?php   function match_from_pos(array $re_tokens, int $re_pos, string $str, int $str_pos): bool { if (is_end($re_tokens, $re_pos)) return true;  if (match_metachar($re_tokens, $re_pos, \"$\")) return is_end($str, $str_pos);  if (match_metachar($re_tokens, $re_pos + 1, \"*\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (!is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"+\")) return match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; (match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1) || match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"?\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1));  return !is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 1, $str, $str_pos + 1); }<\/code><\/pre>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>match_from_pos<\/strong>(ition) \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438. \u041b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:\u00a0<\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043a\u043e\u043d\u0435\u0446 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f true, \u0442\u0430\u043a \u043a\u0430\u043a \u043b\u044e\u0431\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>$<\/strong>&#171;, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043b\u0438 \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>*<\/strong>&#187; (0 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430), \u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u0441 0 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439). \u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439 \u0432 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e, \u0442\u043e \u0441\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>+<\/strong>&#187; (1 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430), \u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043b\u0438 (\u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u043b) \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>?<\/strong>&#187; (0 \u0438\u043b\u0438 1 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430), \u0442\u043e \u043a\u0430\u043a \u0438 \u0432 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0441 &#171;<strong>*<\/strong>&#171;, \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439 0 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438, \u0441\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u043f\u0440\u0438 \u0438\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438 \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442, \u0441\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u0445 \u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0441\u0442\u0430\u0432\u0448\u0430\u044f\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0430\u043c\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u0435 &#8212; \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u043b\u0438 \u043f\u043e\u0442\u043e\u043a\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430 \u0438 \u0432\u044b\u0432\u043e\u0434 \u0441\u043e\u0432\u043f\u0430\u0432\u0448\u0438\u0445 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<pre><code class=\"php\">&lt;?php   function grep($file, array $re_tokens, string $fname = \"\"): void { $line = 0; while (($str = fgets($file)) !== false &amp;&amp; ++$line) if (re_match($re_tokens, $str = rtrim($str, \"\\r\\n\"))) echo ($fname ? \"{$fname}:\" : \"\") . \"{$line}:{$str}\\n\"; }  if ($argc &lt; 2) exit(\"Usage: {$argv[0]} pattern [file1 file2 ...]\\n\");  $re_tokens = tokenize($argv[1]);  if ($argc == 2) { grep(STDIN, $re_tokens); } else { for ($i = 2; $i &lt; $argc; $i++) { if (is_dir($argv[$i])) { fwrite(STDERR, \"{$argv[0]}: {$argv[$i]} : Is a directory\\n\"); continue; } $f = @fopen($argv[$i], \"r\"); if ($f === false) { fwrite(STDERR, \"Cannot open file: {$argv[$i]}\\n\"); continue; } grep($f, $re_tokens, $argc > 3 ? $argv[$i] : \"\"); fclose($f); } }<\/code><\/pre>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435\u043c, \u044d\u0442\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043d\u043e\u0441\u0438\u0442 \u0441\u0443\u0433\u0443\u0431\u043e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0439 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u043e\u043c\u0443-\u0442\u043e \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u0441\u044f.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/581336\/\"> https:\/\/habr.com\/ru\/articles\/581336\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u042d\u0442\u0430 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u043e\u0431\u044f\u0437\u0430\u043d\u0430 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c\u0443 \u0437\u0430\u0434\u0430\u043d\u0438\u044e, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b \u0443\u0442\u0438\u043b\u0438\u0442\u044b grep \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 PHP, \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c\u0438 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438. <\/p>\n<p>\u0421\u0442\u0440\u043e\u043a\u0430 \u0441 \u0448\u0430\u0431\u043b\u043e\u043d\u043e\u043c \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u043b\u0430 \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432:<\/p>\n<ul>\n<li>\n<p><strong>^<\/strong> &#8212; \u043d\u0430\u0447\u0430\u043b\u043e \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><strong>$<\/strong> &#8212; \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438<\/p>\n<\/li>\n<li>\n<p><strong>.<\/strong> &#8212; \u043b\u044e\u0431\u043e\u0439 \u0441\u0438\u043c\u0432\u043e\u043b<\/p>\n<\/li>\n<li>\n<p><strong>*<\/strong> &#8212; 0 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437<\/p>\n<\/li>\n<li>\n<p><strong>?<\/strong> &#8212; 0 \u0438\u043b\u0438 1 \u0440\u0430\u0437<\/p>\n<\/li>\n<li>\n<p><strong>+<\/strong> &#8212; 1 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0440\u0430\u0437<\/p>\n<\/li>\n<\/ul>\n<p>\u0422\u0430\u043a \u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 &#8216;\\&#8217;, \u0447\u0442\u043e\u0431\u044b \u043f\u043e \u043d\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a. \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0430\u044f\u0441\u044f \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0441\u0442\u0430 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 70 &#8212; \u044d\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u0433\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u0432 \u0441\u0443\u0433\u0443\u0431\u043e \u043e\u0431\u0443\u0447\u0430\u044e\u0449\u0438\u0445 \u0446\u0435\u043b\u044f\u0445, \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d \u0435\u0435 \u043a\u043e\u0434 \u0438 \u043a\u0440\u0430\u0442\u043a\u0438\u0439 \u0440\u0430\u0437\u0431\u043e\u0440.<\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442: <\/p>\n<details class=\"spoiler\">\n<summary>grep.php<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"php\">#!\/bin\/env php &lt;?php  const META_CHAR = 1, LITERAL = 2, META_CHARS = [\"*\", \"?\", \"+\", \".\"];  function is_metachar(string $re, int $i): bool { return in_array($re[$i], META_CHARS) || ($re[$i] === \"^\" &amp;&amp; $i === 0) || ($re[$i] === \"$\" &amp;&amp; $i === (strlen($re) - 1)); }  function tokenize(string $re, int $i = 0): array { $re_tokens = []; $len = strlen($re); while ($i &lt; $len) { if ($re[$i] === '\\\\' &amp;&amp; $i + 1 &lt; $len &amp;&amp; (is_metachar($re, $i + 1) || ($i === 0 &amp;&amp; $re[$i + 1] === \"^\"))) $re_tokens[] = [LITERAL, $re[++$i]]; else $re_tokens[] = [is_metachar($re, $i) ? META_CHAR : LITERAL, $re[$i]]; $i++; } return $re_tokens; }  function match_char(array $re_char, string $str_char): bool { return ($re_char[0] === LITERAL &amp;&amp; $re_char[1] === $str_char) || ($re_char[0] === META_CHAR &amp;&amp; $re_char[1] === \".\"); }  function match_metachar(array $tokens, int $pos, string $char): bool { return isset($tokens[$pos]) &amp;&amp; $tokens[$pos][0] === META_CHAR &amp;&amp; $tokens[$pos][1] === $char; }  function is_end($data, int $pos): bool { return !isset($data[$pos]); }  function re_match(array $re_tokens, string $str, int $str_pos = 0): bool { if (match_metachar($re_tokens, 0, \"^\")) return match_from_pos($re_tokens, 1, $str, 0);  $match = false; while (!$match &amp;&amp; !is_end($str, $str_pos)) $match = match_from_pos($re_tokens, 0, $str, $str_pos++); return $match; }  function match_from_pos(array $re_tokens, int $re_pos, string $str, int $str_pos): bool { if (is_end($re_tokens, $re_pos)) return true;  if (match_metachar($re_tokens, $re_pos, \"$\")) return is_end($str, $str_pos);  if (match_metachar($re_tokens, $re_pos + 1, \"*\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (!is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"+\")) return match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; (match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1) || match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"?\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1));  return !is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 1, $str, $str_pos + 1); }  function grep($file, array $re_tokens, string $fname = \"\"): void { $line = 0; while (($str = fgets($file)) !== false &amp;&amp; ++$line) if (re_match($re_tokens, $str = rtrim($str, \"\\r\\n\"))) echo ($fname ? \"{$fname}:\" : \"\") . \"{$line}:{$str}\\n\"; }  if ($argc &lt; 2) exit(\"Usage: {$argv[0]} pattern [file1 file2 ...]\\n\");  $re_tokens = tokenize($argv[1]);  if ($argc == 2) { grep(STDIN, $re_tokens); } else { for ($i = 2; $i &lt; $argc; $i++) { if (is_dir($argv[$i])) { fwrite(STDERR, \"{$argv[0]}: {$argv[$i]} : Is a directory\\n\"); continue; } $f = @fopen($argv[$i], \"r\"); if ($f === false) { fwrite(STDERR, \"Cannot open file: {$argv[$i]}\\n\"); continue; } grep($f, $re_tokens, $argc > 3 ? $argv[$i] : \"\"); fclose($f); } }<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b: <\/p>\n<pre><code class=\"bash\">.\/grep.php '^funct+is?.*pos.*$.*bool$' grep.php 30:function match_metachar(array $tokens, int $pos, string $char): bool 51:function match_from_pos(array $re_tokens, int $re_pos, string $str, int $str_pos): bool<\/code><\/pre>\n<p>\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0441\u0442\u0438 \u0440\u0430\u0437\u0431\u043e\u0440 \u0441\u0442\u0440\u043e\u043a\u0438 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c \u043d\u0430 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0438 \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u044b. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0441\u043b\u0443\u0436\u0438\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044f <strong>tokenize<\/strong>:<\/p>\n<pre><code class=\"php\">&lt;?php  const META_CHAR = 1, LITERAL = 2, META_CHARS = [\"*\", \"?\", \"+\", \".\"];  function is_metachar(string $re, int $i): bool { return in_array($re[$i], META_CHARS) || ($re[$i] === \"^\" &amp;&amp; $i === 0) || ($re[$i] === \"$\" &amp;&amp; $i === (strlen($re) - 1)); }  function tokenize(string $re, int $i = 0): array { $re_tokens = []; $len = strlen($re); while ($i &lt; $len) { if ($re[$i] === '\\\\' &amp;&amp; $i + 1 &lt; $len &amp;&amp; (is_metachar($re, $i + 1) || ($i === 0 &amp;&amp; $re[$i + 1] === \"^\"))) $re_tokens[] = [LITERAL, $re[++$i]]; else $re_tokens[] = [is_metachar($re, $i) ? META_CHAR : LITERAL, $re[$i]]; $i++; } return $re_tokens; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c, \u043f\u0440\u043e\u0431\u0435\u0433\u0430\u0435\u0442 \u043f\u043e \u043a\u0430\u0436\u0434\u043e\u043c\u0443 \u0441\u0438\u043c\u0432\u043e\u043b\u0443 \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0442\u0438\u043f \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a \u043c\u0430\u0441\u0441\u0438\u0432\u0443 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432. \u0415\u0441\u043b\u0438 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d (\u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c \u0441\u0442\u043e\u0438\u0442 \u0441\u043b\u0435\u0448 &#171;<strong>\\<\/strong>&#171;), \u0442\u043e \u043e\u043d \u0441\u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044b\u0447\u043d\u044b\u043c \u043b\u0438\u0442\u0435\u0440\u0430\u043b\u043e\u043c. \u0422\u0430\u043a \u0436\u0435 \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <strong>^<\/strong> \u0438 <strong>$<\/strong> \u0441\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0440\u0430\u0441\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u0438 \u043a\u043e\u043d\u0446\u0435 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e.<\/p>\n<pre><code class=\"php\">&lt;?php  function match_char(array $re_char, string $str_char): bool { return ($re_char[0] === LITERAL &amp;&amp; $re_char[1] === $str_char) || ($re_char[0] === META_CHAR &amp;&amp; $re_char[1] === \".\"); }  function match_metachar(array $tokens, int $pos, string $char): bool { return isset($tokens[$pos]) &amp;&amp; $tokens[$pos][0] === META_CHAR &amp;&amp; $tokens[$pos][1] === $char; }  function is_end($data, int $pos): bool { return !isset($data[$pos]); }  function re_match(array $re_tokens, string $str, int $str_pos = 0): bool { if (match_metachar($re_tokens, 0, \"^\")) return match_from_pos($re_tokens, 1, $str, 0);  $match = false; while (!$match &amp;&amp; !is_end($str, $str_pos)) $match = match_from_pos($re_tokens, 0, $str, $str_pos++); return $match; }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <strong>re_match<\/strong> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>tokenize<\/strong> \u0438 \u0441\u0442\u0440\u043e\u043a\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0437\u0438\u0446\u0438\u044e, \u0441 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 0). \u0415\u0441\u043b\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0441 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b\u0430 &#171;<strong>^<\/strong>&#171;, \u0442\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0433\u043e\u0441\u044f \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0433\u043e \u0441 \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438.\u00a0\u0412 \u0438\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0438\u0441\u043a \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0432 \u043b\u044e\u0431\u043e\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 (\u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 \u0441\u0434\u0432\u0438\u0433\u0430\u044f \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430 \u043e\u0434\u0438\u043d \u0441\u0438\u043c\u0432\u043e\u043b, \u043f\u043e\u043a\u0430 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043a\u043e\u043d\u0435\u0446).<\/p>\n<pre><code class=\"php\">&lt;?php   function match_from_pos(array $re_tokens, int $re_pos, string $str, int $str_pos): bool { if (is_end($re_tokens, $re_pos)) return true;  if (match_metachar($re_tokens, $re_pos, \"$\")) return is_end($str, $str_pos);  if (match_metachar($re_tokens, $re_pos + 1, \"*\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (!is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"+\")) return match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; (match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1) || match_from_pos($re_tokens, $re_pos, $str, $str_pos + 1));  if (match_metachar($re_tokens, $re_pos + 1, \"?\")) return match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos) || (match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 2, $str, $str_pos + 1));  return !is_end($str, $str_pos) &amp;&amp; match_char($re_tokens[$re_pos], $str[$str_pos]) &amp;&amp; match_from_pos($re_tokens, $re_pos + 1, $str, $str_pos + 1); }<\/code><\/pre>\n<p>\u0412 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <strong>match_from_pos<\/strong>(ition) \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439 \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0438. \u041b\u043e\u0433\u0438\u043a\u0443 \u0440\u0430\u0431\u043e\u0442\u044b \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:\u00a0<\/p>\n<ol>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043a\u043e\u043d\u0435\u0446 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f true, \u0442\u0430\u043a \u043a\u0430\u043a \u043b\u044e\u0431\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0443\u0441\u0442\u043e\u043c\u0443 \u0448\u0430\u0431\u043b\u043e\u043d\u0443.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>$<\/strong>&#171;, \u0442\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442 \u043b\u0438 \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>*<\/strong>&#187; (0 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430), \u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e\u0433\u043e \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0447\u0442\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u0441 0 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439). \u0415\u0441\u043b\u0438 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439 \u0432 \u043e\u0441\u0442\u0430\u0432\u0448\u0435\u0439\u0441\u044f \u0447\u0430\u0441\u0442\u0438 \u043d\u0435 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u043e, \u0442\u043e \u0441\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u044e \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0432 \u0441\u0442\u0440\u043e\u043a\u0435 (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0439).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>+<\/strong>&#187; (1 \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430), \u0442\u043e \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438, \u0430 \u0437\u0430\u0442\u0435\u043c \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u043e\u0441\u0442\u0430\u0432\u0448\u0443\u044e\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u043b\u0438 (\u0435\u0441\u043b\u0438 \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435 \u0441\u043e\u0432\u043f\u0430\u043b) \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u043f\u043e\u0437\u0438\u0446\u0438\u044e \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0433\u043e \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 (\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0443 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u044f).<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0435\u0439 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043c\u0435\u0442\u0430\u0441\u0438\u043c\u0432\u043e\u043b &#171;<strong>?<\/strong>&#187; (0 \u0438\u043b\u0438 1 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u0441\u0438\u043c\u0432\u043e\u043b\u0430), \u0442\u043e \u043a\u0430\u043a \u0438 \u0432 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0435 \u0441 &#171;<strong>*<\/strong>&#171;, \u0432 \u043d\u0430\u0447\u0430\u043b\u0435 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439 0 \u043f\u043e\u0432\u0442\u043e\u0440\u0435\u043d\u0438\u0439, \u0430 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0435\u0443\u0434\u0430\u0447\u0438, \u0441\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u043f\u0440\u0438 \u0438\u0445 \u0441\u043e\u0432\u043f\u0430\u0434\u0435\u043d\u0438\u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 &#8212; \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u043c, \u0447\u0442\u043e \u043a\u043e\u043d\u0435\u0446 \u0441\u0442\u0440\u043e\u043a\u0438 \u0435\u0449\u0435 \u043d\u0435 \u0434\u043e\u0441\u0442\u0438\u0433\u043d\u0443\u0442, \u0441\u0432\u0435\u0440\u044f\u0435\u043c \u0441\u0438\u043c\u0432\u043e\u043b\u044b \u0432 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u043f\u043e\u0437\u0438\u0446\u0438\u044f\u0445 \u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u043f\u043e\u0437\u0438\u0446\u0438\u0438.<\/p>\n<\/li>\n<\/ol>\n<p>\u041e\u0441\u0442\u0430\u0432\u0448\u0430\u044f\u0441\u044f \u0447\u0430\u0441\u0442\u044c \u043a\u043e\u0434\u0430 \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u043a \u0441\u0430\u043c\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u0435 &#8212; \u043e\u0431\u044b\u0447\u043d\u043e\u0435 \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438\u043b\u0438 \u043f\u043e\u0442\u043e\u043a\u0430 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430 \u0438 \u0432\u044b\u0432\u043e\u0434 \u0441\u043e\u0432\u043f\u0430\u0432\u0448\u0438\u0445 \u0441\u0442\u0440\u043e\u043a.<\/p>\n<pre><code class=\"php\">&lt;?php   function grep($file, array $re_tokens, string $fname = \"\"): void { $line = 0; while (($str = fgets($file)) !== false &amp;&amp; ++$line) if (re_match($re_tokens, $str = rtrim($str, \"\\r\\n\"))) echo ($fname ? \"{$fname}:\" : \"\") . \"{$line}:{$str}\\n\"; }  if ($argc &lt; 2) exit(\"Usage: {$argv[0]} pattern [file1 file2 ...]\\n\");  $re_tokens = tokenize($argv[1]);  if ($argc == 2) { grep(STDIN, $re_tokens); } else { for ($i = 2; $i &lt; $argc; $i++) { if (is_dir($argv[$i])) { fwrite(STDERR, \"{$argv[0]}: {$argv[$i]} : Is a directory\\n\"); continue; } $f = @fopen($argv[$i], \"r\"); if ($f ===<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-385530","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/385530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=385530"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/385530\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=385530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=385530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=385530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}