{"id":275181,"date":"2016-02-29T18:36:02","date_gmt":"2016-02-29T15:36:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=275181"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=275181","title":{"rendered":"ORegex: \u041e\u0442 \u0441\u0438\u043c\u0432\u043e\u043b\u043e\u0432 \u043a \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c"},"content":{"rendered":"<p>       \u0414\u043e\u0431\u0440\u044b\u0439 \u0432\u0435\u0447\u0435\u0440, \u0445\u0430\u0431\u0440\u043e\u0436\u0438\u0442\u0435\u043b\u0438!<br \/>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0442\u0430\u043a\u0438\u043c \u0435\u0449\u0435 \u043c\u043e\u043b\u043e\u0434\u044b\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c, \u043a\u0430\u043a ORegex \u0438\u043b\u0438 Object Regular Expressions. \u042f \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u043b\u0438\u043d\u0433\u0432\u0438\u0441\u0442\u0438\u043a\u0435 \u0438 \u0445\u043e\u0442\u044c \u044f \u043d\u0435 \u043b\u0438\u043d\u0433\u0432\u0438\u0441\u0442, \u043d\u043e \u0432\u0441\u0435 \u0436\u0435 \u0432\u0438\u0436\u0443 \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0443\u0441\u0442\u043e\u044f\u0432\u0448\u0438\u0435\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u0448\u0430\u0431\u043b\u043e\u043d\u044b.<br \/>  \u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0445 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442.<br \/>  <a name=\"habracut\"><\/a><br \/>  \u042d\u0442\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438:  <\/p>\n<ul>\n<li>\u0421\u043c\u0430\u0439\u043b\u044b;<\/li>\n<li>\u0425\u0435\u0448\u0442\u0435\u0433\u0438;<\/li>\n<li>\u0414\u0430\u0442\u044b;<\/li>\n<li>\u0422\u0435\u043b\u0435\u0444\u043e\u043d\u044b;<\/li>\n<li>\u0438 \u0442.\u0434.<\/li>\n<\/ul>\n<p>  \u0422\u0430\u043a \u0438 \u0441\u043b\u043e\u0436\u043d\u044b\u043c\u0438:  <\/p>\n<ul>\n<li>\u041f\u0440\u044f\u043c\u0430\u044f \u0440\u0435\u0447\u044c;<\/li>\n<li>\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439;<\/li>\n<li>\u0418\u043c\u0435\u043d\u0430;<\/li>\n<li>\u041f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u043a\u0441\u0442\u0435;<\/li>\n<li>\u0438 \u0442.\u0434.<\/li>\n<\/ul>\n<p>  \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043c\u043e\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0438 \u043a\u0430\u043a \u0438\u0437\u0432\u043b\u0435\u0447\u044c \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0433\u0440\u0430\u043c\u043c\u0430\u0442\u0438\u043a\u0438, \u043c\u043e\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u044b, \u0430 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0430\u0440\u0443 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u0446\u0438\u043a\u043b\u043e\u0432. \u041d\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u043d\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043d\u0430\u0434\u043e\u0435\u043b\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0442\u043e\u043d\u043d\u044b \u043f\u0430\u0440\u0441\u0435\u0440\u043e\u0432 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u043d\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 (\u0442\u043e\u043a\u0435\u043d\u044b, \u0441\u043b\u043e\u0432\u0430, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0441\u043b\u043e\u0432 \u0438 \u0442.\u0434.) \u0441 \u0440\u0430\u0437\u043d\u043e\u0439 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0438 \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0431\u0430\u0433\u043e\u0432, \u043c\u043d\u0435 \u043f\u0440\u0438\u0448\u0435\u043b \u0432 \u0433\u043e\u043b\u043e\u0432\u0443 \u0440\u0435\u0437\u043e\u043d\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441 \u2014 \u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u043e\u0449\u0435? \u041e\u0442\u0432\u0435\u0442 \u043f\u0440\u0438\u0448\u0435\u043b \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430. <\/p>\n<p>  \u041d\u043e \u043a\u0430\u043a? \u0420\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0445\u043e\u0440\u043e\u0448\u043e \u0438 \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u043f\u0440\u0430\u0432\u044f\u0442\u0441\u044f \u0441 \u0437\u0430\u0434\u0430\u0447\u0435\u0439 \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u043e \u0448\u0430\u0431\u043b\u043e\u043d\u0443, \u0432\u043e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0441\u0435 \u0434\u0432\u0438\u0436\u043a\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u044b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u0434 \u0441\u0438\u043c\u0432\u043e\u043b\u044c\u043d\u044b\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0430 \u0442\u0435, \u0447\u0442\u043e \u0437\u0430\u0442\u043e\u0447\u0435\u043d\u044b \u043f\u043e\u0434 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0441\u043e\u0432\u0441\u0435\u043c \u043d\u0435 \u0440\u0430\u0434\u0443\u044e\u0442 \u0441\u0432\u043e\u0438\u043c\u0438 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u043d\u044b\u043c\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430\u043c\u0438 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0445 \u043f\u043b\u043e\u0441\u043a\u043e\u0441\u0442\u044f\u0445. \u0412 \u0438\u0442\u043e\u0433\u0435 \u043d\u0435\u0434\u043e\u043b\u0433\u0438\u0445 \u0440\u0430\u0437\u0434\u0443\u043c\u0438\u0439 \u0431\u044b\u043b\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u0432\u043e\u0439 \u00ab\u0432\u0435\u043b\u043e\u0441\u0438\u043f\u0435\u0434 \u0441 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u00bb.<\/p>\n<p>  \u041f\u0440\u043e\u0435\u043a\u0442 \u044f \u0440\u0435\u0448\u0438\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c \u043f\u043e \u0440\u044f\u0434\u0443 \u043f\u0440\u0438\u0447\u0438\u043d, \u043d\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u043d\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u0432\u043e\u043e\u0431\u0449\u0435 \u0435\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0431\u043e\u0435\u0432\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f.<\/p>\n<p>  <b>How to use? <\/b><\/p>\n<p>  \u041d\u0430\u0434 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441\u043e\u043c \u044f \u0434\u043e\u043b\u0433\u043e \u043d\u0435 \u0434\u0443\u043c\u0430\u043b, \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u043d\u043e\u0442\u0430\u0446\u0438\u044e .NET + \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u043c\u0435\u043d\u0430 \u0434\u043b\u044f \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u0439. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u043e \u0431\u044b \u0431\u0435\u0437 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0432\u044b\u043d\u043e\u0441\u0438\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b:<\/p>\n<p>  {MyPredicate1} | (?{MyPredicate2} {MyPredicate3}*)<\/p>\n<p>  \u0421\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442, \u0447\u0442\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 .NET Regex \u043d\u0435 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b (\u0443\u0441\u043b\u043e\u0432\u043d\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b, lookahed), \u043d\u043e \u0432 \u0441\u043a\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043e\u043d\u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f. \u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u0430\u043c\u0438\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c. \u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0447\u0438\u0441\u0435\u043b:<\/p>\n<p>  1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13<\/p>\n<p>  \u0418 \u0412\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u0432\u0441\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0447\u0438\u0441\u043b\u0430. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0412\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0442\u0432\u0435\u0447\u0430\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c, \u043b\u0438\u0431\u043e \u043d\u0435\u0442:<\/p>\n<pre><code class=\"cs\">    private static bool IsPrime(int number)     {         int boundary = (int)Math.Floor(Math.Sqrt(number));         if (number == 1) return false;         if (number == 2) return true;         for (int i = 2; i &lt;= boundary; ++i)         {             if (number % i == 0) return false;         }         return true;     } <\/code><\/pre>\n<p>  \u0418 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439:<\/p>\n<p>  {IsPrime}(.{IsPrime})*<\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c, \u0432 \u043e\u0431\u0449\u0435\u043c \u0438 \u0446\u0435\u043b\u043e\u043c, \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u0430. \u041e\u043f\u0438\u0448\u0435\u043c \u0441\u0430\u043c\u0443 \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">    public void PrimeTest()     {         var oregex = new ORegex&lt;int&gt;(&quot;{0}(.{0})*&quot;, IsPrime);         var input = new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};         foreach (var match in oregex.Matches(input))         {             Console.WriteLine(string.Join(&quot;,&quot;, match.Values));         }          \/\/OUTPUT:         \/\/2         \/\/3,4,5,6,7         \/\/11,12,13     } <\/code><\/pre>\n<p>  \u041d\u0443 \u0432\u043e\u0442 \u0438 \u0432\u0441\u0435, \u043d\u043e \u043d\u0435 \u0442\u0430\u043a \u0443\u0431\u0435\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0434\u0430? \u0425\u043e\u0440\u043e\u0448\u043e, \u0442\u043e\u0433\u0434\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0447\u0438\u043a \u043f\u043e\u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u0430\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0441\u043b\u043e\u0432 \u043f\u0440\u0438\u0448\u0435\u0434\u0448\u0430\u044f \u043a \u043d\u0430\u043c \u0438\u0437 \u043b\u0435\u043a\u0441\u0438\u043a\u043e-\u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u043c\u043e\u0434\u0443\u043b\u044f. \u0412\u043e\u043f\u0440\u043e\u0441, \u043a\u0430\u043a \u043f\u043e \u0431\u044b\u0441\u0442\u0440\u043e\u043c\u0443 \u0432\u044b\u0434\u0435\u043b\u0438\u0442\u044c \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0435\u0440\u0441\u043e\u043d \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438? \u0414\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. <\/p>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u043b\u043e\u0432\u0430 \u0438 \u043f\u0435\u0440\u0441\u043e\u043d\u044b:<\/p>\n<pre><code class=\"cs\">    public enum SemanticType     {         Name,         FamilyName,         Other,     }      public class Word     {         public readonly string Value;         public readonly SemanticType SemType;         public Word(string value, SemanticType semType)         {             Value = value;             SemType = semType;         }     }      public class Person     {         public readonly Word[] Words;         public readonly string Name;         public Person(OMatch&lt;Word&gt; match)         {             Words = match.Values.ToArray();             Name = match.OCaptures[&quot;name&quot;].First().Values.First().Value;             \/\/Now just normalize this name and you are good.         }     } <\/code><\/pre>\n<p>  \u0418 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c <i>\u0432\u0430\u0436\u043d\u0443\u044e<\/i> \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f, \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0442\u044c \u0447\u0442\u043e \u0441\u0442\u0440\u043e\u043a\u0430 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u043e\u043c:<\/p>\n<pre><code class=\"cs\">    private static bool IsInitial(string str)     {         var inp = str.Trim(new[] { '.', ' ', '\\t', '\\n', '\\r' });         return inp.Length == 1 && char.IsUpper(inp[0]);     } <\/code><\/pre>\n<p>  \u0411\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0441\u043b\u043e\u0432, \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432, \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u0430\u0448\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u0435\u0440\u0441\u043e\u043d:<\/p>\n<pre><code class=\"cs\">    public void PersonSelectionTest()     {         \/\/INPUT_TEXT: \u041f\u044f\u0442\u043e\u0447\u043a\u043e\u0432\u0430 \u0422\u0430\u043c\u0430\u0440\u0430 \u0440\u0435\u0448\u0438\u043b\u0430 \u0432\u044b\u0433\u0443\u043b\u044f\u0442\u044c \u0414\u0436\u0435\u043a\u0430 \u0438 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c \u0441 \u041c\u0438\u0445\u0430\u0438\u043b\u043e\u043c \u0410.\u041c.         var sentence = new Word[]         {             new Word(&quot;\u041f\u044f\u0442\u043e\u0447\u043a\u043e\u0432\u0430&quot;, SemanticType.FamilyName),             new Word(&quot;\u0422\u0430\u043c\u0430\u0440\u0430&quot;, SemanticType.Name),             new Word(&quot;\u0440\u0435\u0448\u0438\u043b\u0430&quot;,  SemanticType.Other),             new Word(&quot;\u0432\u044b\u0433\u0443\u043b\u044f\u0442\u044c&quot;, SemanticType.Other),             new Word(&quot;\u0414\u0436\u0435\u043a\u0430&quot;, SemanticType.Name),             new Word(&quot;\u0438&quot;, SemanticType.Other),             new Word(&quot;\u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043b\u0430\u0441\u044c&quot;, SemanticType.Other),             new Word(&quot;\u0441&quot;, SemanticType.Other),             new Word(&quot;\u041c\u0438\u0445\u0430\u0438\u043b\u043e\u043c&quot;, SemanticType.Name),             new Word(&quot;\u0410.&quot;, SemanticType.Other),             new Word(&quot;\u041c&quot;, SemanticType.Other),         };          \/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432.         var pTable = new PredicateTable&lt;Word&gt;();         pTable.AddPredicate(&quot;\u0424\u0430\u043c\u0438\u043b\u0438\u044f&quot;, x =&gt; x.SemType == SemanticType.FamilyName);  \/\/Check if word is FamilyName.         pTable.AddPredicate(&quot;\u0418\u043c\u044f&quot;, x =&gt; x.SemType == SemanticType.Name);            \/\/Check if word is simple Name.         pTable.AddPredicate(&quot;\u0418\u043d\u0438\u0446\u0438\u0430\u043b&quot;, x =&gt; IsInitial(x.Value));                    \/\/Complex check if Value is Inital character.          \/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043d\u0430\u0448\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.         var oregex = new ORegex&lt;Word&gt;(@&quot;             {\u0424\u0430\u043c\u0438\u043b\u0438\u044f}(?&lt;name&gt;{\u0418\u043c\u044f})                     \/\/Comments can be written inside pattern...             |             (?&lt;name&gt;{\u0418\u043c\u044f})({\u0424\u0430\u043c\u0438\u043b\u0438\u044f}|{\u0418\u043d\u0438\u0446\u0438\u0430\u043b}{1,2})?  \/*...even complex ones.*\/         &quot;, pTable);          \/\/\u0412\u044b\u0434\u0435\u043b\u044f\u0435\u043c \u043f\u0435\u0440\u0441\u043e\u043d \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438.         var persons = oregex.Matches(sentence).Select(x =&gt; new Person(x)).ToArray();          foreach (var person in persons)         {             Console.WriteLine(&quot;Person found: {0}, length: {1}&quot;, person.Name, person.Words.Length);         }          \/\/OUTPUT:         \/\/Person found: \u0422\u0430\u043c\u0430\u0440\u0430, length: 2         \/\/Person found: \u0414\u0436\u0435\u043a\u0430, length: 1         \/\/Person found: \u041c\u0438\u0445\u0430\u0438\u043b\u043e\u043c, length: 3     } <\/code><\/pre>\n<p>  \u041d\u0443 \u0432\u043e\u0442 \u0438 \u0432\u0441\u0435. \u041f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u0438 \u0434\u043e\u0445\u043e\u0434\u0447\u0438\u0432\u043e =)<br \/>  \u0415\u0441\u043b\u0438 \u0447\u0442\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043a\u0430\u043a \u0432 <a href=\"https:\/\/www.nuget.org\/packages\/ORegex\/\">nuget<\/a> \u0442\u0430\u043a \u0438 \u043d\u0430 <a href=\"https:\/\/github.com\/eocron\/ORegex\">github<\/a>.               <\/p>\n<div class=\"clear\"><\/div>\n<p> \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:\/\/habrahabr.ru\/post\/278219\/\"> https:\/\/habrahabr.ru\/post\/278219\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0414\u043e\u0431\u0440\u044b\u0439 \u0432\u0435\u0447\u0435\u0440, \u0445\u0430\u0431\u0440\u043e\u0436\u0438\u0442\u0435\u043b\u0438!<br \/>  \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u044f \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0442\u0430\u043a\u0438\u043c \u0435\u0449\u0435 \u043c\u043e\u043b\u043e\u0434\u044b\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u043e\u043c, \u043a\u0430\u043a ORegex \u0438\u043b\u0438 Object Regular Expressions. \u042f \u0443\u0436\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0432 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0439 \u043b\u0438\u043d\u0433\u0432\u0438\u0441\u0442\u0438\u043a\u0435 \u0438 \u0445\u043e\u0442\u044c \u044f \u043d\u0435 \u043b\u0438\u043d\u0433\u0432\u0438\u0441\u0442, \u043d\u043e \u0432\u0441\u0435 \u0436\u0435 \u0432\u0438\u0436\u0443 \u0432 \u044f\u0437\u044b\u043a\u0430\u0445 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u0443\u0441\u0442\u043e\u044f\u0432\u0448\u0438\u0435\u0441\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u0448\u0430\u0431\u043b\u043e\u043d\u044b.<br \/>  \u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u043a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u0438\u0445 \u0432\u044b\u0434\u0435\u043b\u044f\u0442\u044c \u2014 \u043f\u043e\u0434 \u043a\u0430\u0442.  <\/p>\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-275181","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275181","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=275181"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/275181\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=275181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=275181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=275181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}