Exemplo n.º 1
0
        /// <summary>
        /// Grepを行う
        /// </summary>
        /// <param name="dirPath">フォルダのパス。</param>
        /// <param name="pattern">検索する正規表現のパターン。</param>
        /// <param name="fileWildcards">対象とするファイル。</param>
        /// <param name="ignoreCase">大文字小文字を区別するか。</param>
        /// <returns>見つかったファイルパスの配列。</returns>
        public static string[] Grep(
            string dirPath, string pattern, string fileWildcards, bool ignoreCase)
        {
            System.Collections.ArrayList fileCol =
                new System.Collections.ArrayList();

            //正規表現のオプションを設定
            System.Text.RegularExpressions.RegexOptions opts =
                System.Text.RegularExpressions.RegexOptions.None;
            if (ignoreCase)
            {
                opts |= System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            }
            System.Text.RegularExpressions.Regex reg =
                new System.Text.RegularExpressions.Regex(pattern, opts);

            //フォルダ内にあるファイルを取得
            System.IO.DirectoryInfo dir   = new System.IO.DirectoryInfo(dirPath);
            System.IO.FileInfo[]    files = dir.GetFiles(fileWildcards);
            foreach (System.IO.FileInfo f in files)
            {
                //一つずつファイルを調べる
                if (ContainTextInFile(f.FullName, reg))
                {
                    fileCol.Add(f.FullName);
                }
            }

            return((string[])fileCol.ToArray(typeof(string)));
        }
Exemplo n.º 2
0
        private string GetObjectDefinition(string type, string name, string definition)
        {
            string rv = definition;

            string sqlDelimiters = @"(\r|\n|\s)*?";

            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline;
            System.Text.RegularExpressions.Regex        re      = new System.Text.RegularExpressions.Regex(@"CREATE" + sqlDelimiters + @"PROC(EDURE)?" + sqlDelimiters + @"(\w+\.|\[\w+\]\.)?\[?(?<spname>\w+)\]?" + sqlDelimiters, options);
            switch (type)
            {
            case "P":
                System.Text.RegularExpressions.Match match = re.Match(definition);
                if (match != null && match.Success)
                {
                    // Try to replace the name saved in the definition when the object was created by the one used for the object in sys.object
                    string oldName = match.Groups["spname"].Value;
                    //if (String.IsNullOrEmpty(oldName)) System.Diagnostics.Debugger.Break();
                    if (String.Compare(oldName, name) != 0)
                    {
                        rv = rv.Replace(oldName, name);
                    }
                }
                break;

            default:
                //TODO : Add the logic used for other objects than procedures
                break;
            }

            return(rv);
        }
Exemplo n.º 3
0
        static UriUtility()
        {
#if PORTABLE
            if (!Enum.TryParse("Compiled", out DefaultRegexOptions))
                DefaultRegexOptions = RegexOptions.None;
#else
            DefaultRegexOptions = RegexOptions.Compiled;
#endif

            _unreservedCharacters = new BitArray(256);
            for (char i = 'a'; i <= 'z'; i++)
                _unreservedCharacters.Set(i, true);
            for (char i = 'A'; i <= 'Z'; i++)
                _unreservedCharacters.Set(i, true);
            for (char i = '0'; i <= '9'; i++)
                _unreservedCharacters.Set(i, true);
            _unreservedCharacters.Set('-', true);
            _unreservedCharacters.Set('.', true);
            _unreservedCharacters.Set('_', true);
            _unreservedCharacters.Set('~', true);

            _generalDelimiters = new BitArray(256);
            _generalDelimiters.Set(':', true);
            _generalDelimiters.Set('/', true);
            _generalDelimiters.Set('?', true);
            _generalDelimiters.Set('#', true);
            _generalDelimiters.Set('[', true);
            _generalDelimiters.Set(']', true);
            _generalDelimiters.Set('@', true);

            _subDelimiters = new BitArray(256);
            _subDelimiters.Set('!', true);
            _subDelimiters.Set('$', true);
            _subDelimiters.Set('&', true);
            _subDelimiters.Set('(', true);
            _subDelimiters.Set(')', true);
            _subDelimiters.Set('*', true);
            _subDelimiters.Set('+', true);
            _subDelimiters.Set(',', true);
            _subDelimiters.Set(';', true);
            _subDelimiters.Set('=', true);
            _subDelimiters.Set('\'', true);

            _reservedCharacters = new BitArray(256).Or(_generalDelimiters).Or(_subDelimiters);

            _allowedHostCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters);

            _allowedPathCharacters = new BitArray(256).Or(_unreservedCharacters).Or(_subDelimiters);
            _allowedPathCharacters.Set(':', true);
            _allowedPathCharacters.Set('@', true);

            _allowedQueryCharacters = new BitArray(256).Or(_allowedPathCharacters);
            _allowedQueryCharacters.Set('/', true);
            _allowedQueryCharacters.Set('?', true);

            _allowedFragmentCharacters = new BitArray(256).Or(_allowedPathCharacters);
            _allowedFragmentCharacters.Set('/', true);
            _allowedFragmentCharacters.Set('?', true);
        }
Exemplo n.º 4
0
 public static String RemoveHtmlTag(String Html)
 {
     System.Text.RegularExpressions.RegexOptions Option = System.Text.RegularExpressions.RegexOptions.IgnoreCase;
     Html = System.Text.RegularExpressions.Regex.Replace(Html, "<br[^>]*>", "\r\n", Option);
     Html = System.Text.RegularExpressions.Regex.Replace(Html, "<[^>]*>", String.Empty, Option);
     Html = Html.Replace("&euro", "€");
     return(System.Web.HttpUtility.HtmlDecode(Html));
 }
        public void Do()
        {
            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.None;

            System.DateTime dt = default(System.DateTime);

            var list = new System.Collections.Generic.List <object>();
        }
Exemplo n.º 6
0
        bool FindStringInRow(string SearchInString, String Find, bool bMatchCase, bool bMatchCell, int iSearchMethod)
        {
            // Regular string search
            if (iSearchMethod == 0)
            {
                // Match Cell
                if (bMatchCell)
                {
                    if (!bMatchCase)
                    {
                        if (SearchInString.ToLowerInvariant() == Find.ToLowerInvariant())
                        {
                            return(true);
                        }
                        else
                        if (SearchInString == Find)
                        {
                            return(true);
                        }
                    }
                }
                // No Match Cell
                else
                {
                    StringComparison strCompare = StringComparison.InvariantCulture;
                    if (!bMatchCase)
                    {
                        strCompare = StringComparison.InvariantCultureIgnoreCase;
                    }
                    return(SearchInString.IndexOf(Find, 0, strCompare) != -1);
                }
            }
            else
            {
                // Regular Expression
                String RegexPattern = Find;
                // Wildcards
                if (iSearchMethod == 2)
                {
                    // Convert wildcard to regex:
                    RegexPattern = "^" + System.Text.RegularExpressions.Regex.Escape(Find).Replace("\\*", ".*").Replace("\\?", ".") + "$";
                }

                System.Text.RegularExpressions.RegexOptions strCompare = System.Text.RegularExpressions.RegexOptions.None;
                if (!bMatchCase)
                {
                    strCompare = System.Text.RegularExpressions.RegexOptions.IgnoreCase;
                }

                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(RegexPattern, strCompare);
                if (regex.IsMatch(SearchInString))
                {
                    return(true);
                }
                return(false);
            }
            return(false);
        }
Exemplo n.º 7
0
        public static String HtmlReplaceNbspToBR(String Html)
        {
            const string regPSpan      = @"(<p.*><span.*>)&nbsp;(<\/span><\/p>)";
            const string replaceString = @"$1<br/>$2";

            System.Text.RegularExpressions.RegexOptions Option = System.Text.RegularExpressions.RegexOptions.IgnoreCase;

            return(System.Text.RegularExpressions.Regex.Replace(Html, regPSpan, replaceString, Option));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 从指定的 HTML 文本中清除脚本标签“SCRIPT”。
        /// </summary>
        /// <param name="html">具有 HTML 格式的代码文本。</param>
        /// <returns>清除“SCRIPT”标签后的返回值。</returns>
        /// <example>
        /// <para lang="C#">
        /// 下面的代码演示了如何使用这个方法:
        /// </para>
        /// <code lang="C#">
        /// <![CDATA[this.Response.Write(RemoveScriptLable(@"
        /// <script language=javascript>
        /// alert('ok');
        /// </script>
        /// abc"));
        /// ]]>
        /// </code>
        /// <para lang="C#">
        /// 输出结果:
        /// <br/>abc
        /// </para>
        /// </example>
        public static string RemoveScriptLable(string html)
        {
            System.Text.RegularExpressions.RegexOptions regexOptions = System.Text.RegularExpressions.RegexOptions.ExplicitCapture | System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.IgnoreCase;

            string reSCRIPT = @"<SCRIPT(?:[^>]*)>(?:.*?)</SCRIPT>";

            html = System.Text.RegularExpressions.Regex.Replace(html, reSCRIPT, "", regexOptions);

            return(html);
        }
Exemplo n.º 9
0
    static int Split(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(System.Text.RegularExpressions.Regex), typeof(string)))
        {
            System.Text.RegularExpressions.Regex obj = (System.Text.RegularExpressions.Regex)LuaScriptMgr.GetNetObjectSelf(L, 1, "System.Text.RegularExpressions.Regex");
            string   arg0 = LuaScriptMgr.GetString(L, 2);
            string[] o    = obj.Split(arg0);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(string)))
        {
            string   arg0 = LuaScriptMgr.GetString(L, 1);
            string   arg1 = LuaScriptMgr.GetString(L, 2);
            string[] o    = System.Text.RegularExpressions.Regex.Split(arg0, arg1);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(System.Text.RegularExpressions.Regex), typeof(string), typeof(int)))
        {
            System.Text.RegularExpressions.Regex obj = (System.Text.RegularExpressions.Regex)LuaScriptMgr.GetNetObjectSelf(L, 1, "System.Text.RegularExpressions.Regex");
            string   arg0 = LuaScriptMgr.GetString(L, 2);
            int      arg1 = (int)LuaDLL.lua_tonumber(L, 3);
            string[] o    = obj.Split(arg0, arg1);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(string), typeof(string), typeof(System.Text.RegularExpressions.RegexOptions)))
        {
            string arg0 = LuaScriptMgr.GetString(L, 1);
            string arg1 = LuaScriptMgr.GetString(L, 2);
            System.Text.RegularExpressions.RegexOptions arg2 = (System.Text.RegularExpressions.RegexOptions)LuaScriptMgr.GetLuaObject(L, 3);
            string[] o = System.Text.RegularExpressions.Regex.Split(arg0, arg1, arg2);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else if (count == 4)
        {
            System.Text.RegularExpressions.Regex obj = (System.Text.RegularExpressions.Regex)LuaScriptMgr.GetNetObjectSelf(L, 1, "System.Text.RegularExpressions.Regex");
            string   arg0 = LuaScriptMgr.GetLuaString(L, 2);
            int      arg1 = (int)LuaScriptMgr.GetNumber(L, 3);
            int      arg2 = (int)LuaScriptMgr.GetNumber(L, 4);
            string[] o    = obj.Split(arg0, arg1, arg2);
            LuaScriptMgr.PushArray(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: System.Text.RegularExpressions.Regex.Split");
        }

        return(0);
    }
Exemplo n.º 10
0
        public static bool send(string to, string message, HttpServerUtilityBase server, string from_name = "Default")
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(server.MapPath("~/Models/Mail.xml"));

            XmlNodeList nodes = doc.GetElementsByTagName("Mail");

            foreach (XmlElement node in nodes)
            {
                if (node.FirstChild.InnerText == from_name)
                {
                    from_port   = int.Parse(node.FirstChild.NextSibling.NextSibling.NextSibling.InnerText);
                    from        = node.FirstChild.NextSibling.InnerText;
                    from_pwd    = node.FirstChild.NextSibling.NextSibling.InnerText;
                    from_server = node.FirstChild.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    break;
                }
                else
                {
                    continue;
                }
            }

            string regexEmail = @"^\w+([-+.]?\w+)*@\w+([-.]?\w+)*\.\w+([-.]?\w+)*$ ";

            System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace
                                                                    | System.Text.RegularExpressions.RegexOptions.Multiline)
                                                                   | System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regEmail = new System.Text.RegularExpressions.Regex(regexEmail, options);

            if (!regEmail.IsMatch(to))   //email 填写符合正则表达式 "\\w{1,}@\\w{1,}\\.\\w{1,}"
            {
                return(false);
            }

            SmtpClient client = new SmtpClient();

            //获取或设置用于验证发件人身份的凭据。
            client.Credentials = new System.Net.NetworkCredential(from, from_pwd);
            //经过ssl(安全套接层)加密,163邮箱SSL协议端口号为465/994,关闭SSL时端口为25,
            //qq邮箱SSL协议端口号为465或587,关闭SSL时端口同样为25,不过用SSL加密后发送邮件都失败,具体原因不知
            //client.EnableSsl = true;
            client.Port = from_port;       //端口号
            client.Host = from_server;     //获取或设置用于 SMTP 事务的主机的名称或 IP 地址
            try
            {
                client.Send(InitMailMessage(to, message));
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                throw ex;
            }
            return(true);
        }
Exemplo n.º 11
0
        internal void ReplaceAll()
        {
            UpdateLastWordsList(this.tbTextToReplace);
            if (findSuccess)
            {
                System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.None;
                if (!cbMathCase.Checked)
                {
                    options = options | System.Text.RegularExpressions.RegexOptions.IgnoreCase;
                }
                if (cbSearchUp.Checked)
                {
                    options = options | System.Text.RegularExpressions.RegexOptions.RightToLeft;
                }
                string pattern = this.tbTextToFind.Text;
                if (pattern == "")
                {
                    findSuccess = false;
                    return;
                }
                if (!cbUseRegex.Checked)
                {
                    pattern = System.Text.RegularExpressions.Regex.Escape(pattern);
                }
                if (cbMathWord.Checked)
                {
                    pattern = @"\b" + pattern + @"\b";
                }

                try
                {
                    if (lastSearched == this.tbTextToFind.Text)
                    {
                        int offset = Form1.CurrentSyntaxEditor.TextEditor.ActiveTextAreaControl.Caret.Offset;
                        Form1.CurrentSyntaxEditor.TextEditor.Document.Replace(offset,
                                                                              Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent.Length - offset,
                                                                              System.Text.RegularExpressions.Regex.Replace(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent.Substring(offset), pattern, tbTextToReplace.Text));
                    }
                    else
                    {
                        Form1.CurrentSyntaxEditor.TextEditor.Document.Replace(0, Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent.Length, System.Text.RegularExpressions.Regex.Replace(Form1.CurrentSyntaxEditor.TextEditor.Document.TextContent, pattern, tbTextToReplace.Text));
                    }
                    //Form1.CurrentSyntaxEditor.TextEditor.Document.CommitUpdate();
                }
                catch (Exception e)
                {
                    MessageBox.Show(string.Format(PascalABCCompiler.StringResources.Get("VP_REPLACEFORM_REGEXPERR{0}"), e.Message), PascalABCCompiler.StringResources.Get("!ERROR"), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    findSuccess  = false;
                    lastSearched = null;
                    return;
                }
                lastSearched = null;
                findSuccess  = false;
            }
        }
Exemplo n.º 12
0
    public void TestIgnoreCaseAndMultiline()
    {
        const System.Text.RegularExpressions.RegexOptions expectedOptions =
            System.Text.RegularExpressions.RegexOptions.IgnoreCase |
            System.Text.RegularExpressions.RegexOptions.Multiline;

        var regex = new RegexBuilder()
                    .AnyCharacter()
                    .BuildRegex(IgnoreCase, Multiline);

        Assert.That(regex.Options, Is.EqualTo(expectedOptions));
    }
Exemplo n.º 13
0
        public static string RemoveHtmlTags(string html)
        {
            //  Remove the HTML tags
            System.Text.RegularExpressions.RegexOptions    options = System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            System.Text.RegularExpressions.MatchCollection m       = System.Text.RegularExpressions.Regex.Matches(html, "<.*?>", options);

            for (int i = m.Count - 1; i >= 0; i--)
            {
                string tag = html.Substring(m[i].Index + 1, m[i].Length - 1).Trim().ToLower();
                html = html.Remove(m[i].Index, m[i].Length);
            }
            return(html);
        }
Exemplo n.º 14
0
        /// <summary>
        /// 验证字符串是否合法
        /// </summary>
        /// <param name="syllable">需验证字符串</param>
        /// <param name="regex">正则表达式</param>
        /// <returns></returns>
        private static bool RegexOperation(string syllable, string regex)
        {
            //正则表达式的枚举类型
            System.Text.RegularExpressions.RegexOptions options = (
                (System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace |
                 System.Text.RegularExpressions.RegexOptions.Multiline) |
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            //加载正则表达式到枚举类型上
            System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regex, options);

            //返回验证结果
            return(reg.IsMatch(syllable));
        }
Exemplo n.º 15
0
        /// <summary>
        /// 河蟹敏感字
        /// </summary>
        /// <param name="input">输入的文字</param>
        /// <param name="harmfulWords">敏感字</param>
        /// <param name="replaceTo">将敏感字替换成这个</param>
        /// <returns></returns>
        public static string CleanHarmfulWords(this string input, List <string> harmfulWords, string replaceTo)
        {
            if (string.IsNullOrEmpty(input))
            {
                return("");
            }


            if (harmfulWords == null)
            {
                harmfulWords = new List <string>();
                harmfulWords.Add("法轮功");
                harmfulWords.Add("鸡巴");
                harmfulWords.Add("falungong");
                harmfulWords.Add("屄");
                harmfulWords.Add("操你妈");
            }

            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.IgnoreCase |
                                                                  System.Text.RegularExpressions.RegexOptions.Compiled |
                                                                  System.Text.RegularExpressions.RegexOptions.ExplicitCapture;

            foreach (string censor in harmfulWords)
            {
                string searchPattern;

                if (System.Web.HttpUtility.UrlEncode(censor) == censor)
                {
                    if (-1 == censor.IndexOfAny(new char[] { '\\', '[', '^', '*', '{', '.', '#', '?', '+', '$', '|' }))
                    {
                        searchPattern = String.Format(@"(?<!\[(code|pre)(\s*)\](.*))(\b{0}\b)(?!(.*)\[\/(code|pre)(\s*)\])", censor);
                    }
                    else
                    {
                        searchPattern = censor;
                    }
                }
                else
                {
                    searchPattern = censor;
                }

                //searchPattern = censor;

                //System.Web.HttpContext.Current.Response.Write(searchPattern + "\r\n");
                input = System.Text.RegularExpressions.Regex.Replace(input, searchPattern, replaceTo, options);
            }

            return(input);
        }
Exemplo n.º 16
0
        public static bool CheckEmailValidity(string mail)
        {
            if (string.IsNullOrEmpty(mail))
            {
                return(false);
            }
            else
            {
                System.Text.RegularExpressions.RegexOptions tmpRegexOptions =
                    System.Text.RegularExpressions.RegexOptions.Multiline |
                    System.Text.RegularExpressions.RegexOptions.IgnoreCase |
                    System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace;

                return(System.Text.RegularExpressions.Regex.IsMatch(mail, RegexMailExpression, tmpRegexOptions));
            }
        }
Exemplo n.º 17
0
        public static bool CheckPhoneValidity(string phoneCode)
        {
            if (string.IsNullOrEmpty(phoneCode))
            {
                return(false);
            }
            else
            {
                System.Text.RegularExpressions.RegexOptions tmpRegexOptions =
                    System.Text.RegularExpressions.RegexOptions.Multiline |
                    System.Text.RegularExpressions.RegexOptions.IgnoreCase |
                    System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace;

                return(System.Text.RegularExpressions.Regex.IsMatch(phoneCode, RegexPhoneExpression, tmpRegexOptions));
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// <![CDATA[
        /// 从 HTML 格式文本中截取子字符串。截取前先清除 HTML 标签和脚本标签“SCRIPT”等不可显示代码,同时清除可以解释为空白字符的代码(如:HTML代码中的空格标记“&nbsp;”),只保留可显示文本。
        /// ]]>
        /// </summary>
        /// <param name="input">输入具有 HTML 格式的代码文本。</param>
        /// <param name="maxLength">截取的文本最大长度。</param>
        /// <returns>截取后的子字符串(不包含不可见代码元素)</returns>
        /// <remarks>
        /// <![CDATA[
        /// 截取前先清除 HTML 标签和脚本标签“SCRIPT”等不可显示代码,同时清除可以解释为空白字符的代码(如:HTML代码中的空格标记“&nbsp;”),只保留可显示文本。
        /// ]]>
        /// </remarks>
        /// <example>
        /// <para lang="C#">
        /// 下面的代码演示了如何使用这个方法:
        /// </para>
        /// <code lang="C#">
        /// <![CDATA[this.Response.Write(RemoveHtmlLable(@"
        /// <table id=Table1 align=center border=0>
        /// <tr><TD>用户名</TD></tr>
        /// <TR><TD>密&nbsp;码</TD></TR>
        /// <TR><TD>验证码</TD></TR>
        /// </table>", 8));
        /// ]]>
        /// </code>
        /// <para lang="C#">
        /// 输出结果:
        /// <br/>用户名密
        /// </para>
        /// </example>
        public static string HtmlSubstring(string input, int maxLength)
        {
            input = Thinksea.Web.HtmlToText(input);
            System.Text.RegularExpressions.RegexOptions regexOptions = System.Text.RegularExpressions.RegexOptions.ExplicitCapture | System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            input = System.Text.RegularExpressions.Regex.Replace(input, @"^\s+", "", regexOptions);         //删除开头的空白符。
            input = System.Text.RegularExpressions.Regex.Replace(input, @"(\r|\n|\s)+", " ", regexOptions); //回车换行符和空格全部做为一个空格处理。(既要保持文字紧凑,又要兼顾英文单词中间需有一空格。)
            input = Thinksea.Text.Chinese.Substring(input, maxLength);
            return(Thinksea.Web.TextToHtml(input));
            ////此项功能中的代码需要注意执行顺序(例如在从Html代码中清除部分内容后的剩余代码可能重新组合成新的HTML标记),否则可能会引起不宜被发现的错误。
            //System.Text.RegularExpressions.RegexOptions regexOptions = System.Text.RegularExpressions.RegexOptions.ExplicitCapture | System.Text.RegularExpressions.RegexOptions.IgnoreCase;

            //string result = System.Text.RegularExpressions.Regex.Replace( input, "&nbsp;", "", regexOptions );//清除HTML代码中的空格标记“&nbsp;”
            //result = Thinksea.Web.RemoveHtmlLable(result);
            //result = System.Text.RegularExpressions.Regex.Replace( result, @"\s", "", regexOptions );//清除可以解释为空白字符的代码
            //return Thinksea.General.Substring( result, maxLength );
        }
Exemplo n.º 19
0
        internal CodeTemplateBase(
            String patternText,
            RegexOptions options,
            String replacementText,
            String inputText,
            Boolean?multilineInput,
            Model.RegexMethod?regexMethod)
        {
            this.PatternText     = patternText;
            this.ReplacementText = replacementText;
            this.InputText       = inputText;

            var list1 = Enum.GetValues(typeof(RegexOptions))
                        .Cast <RegexOptions>()
                        .Where(o => (options & o) != RegexOptions.None)
                        .Select(o => "RegexOptions." + o.ToString("g"))
                        .ToList();

            if (list1.Count == 0)
            {
                list1.Add("RegexOptions.None");
            }

            this.Options = list1.ToArray();

            var list2 = new List <MethodOptions>();

            foreach (var mi in new Boolean[] { true, false })
            {
                if (multilineInput.HasValue && multilineInput.Value != mi)
                {
                    continue;
                }

                foreach (Model.RegexMethod rm in Enum.GetValues(typeof(Model.RegexMethod)))
                {
                    if (regexMethod.HasValue && regexMethod.Value != rm)
                    {
                        continue;
                    }

                    list2.Add(new MethodOptions(mi, rm));
                }
            }

            this.Methods = list2.ToArray();
        }
Exemplo n.º 20
0
        private string StripAllTags(string content)
        {
            string regex = "<(.|\n)+?>";

            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            System.Text.RegularExpressions.Regex        reg     = new System.Text.RegularExpressions.Regex(regex, options);
            string retVal = content;

            try
            {
                retVal = reg.Replace(content, String.Empty);
            }
            catch
            {             //swallow anything that might go wrong
            }
            return(retVal);
        }
Exemplo n.º 21
0
        public RegexComparer(string pattern, bool ignoreCase) : base(pattern, ignoreCase)
        {
            System.Text.RegularExpressions.RegexOptions opts = System.Text.RegularExpressions.RegexOptions.Compiled;
            if (IgnoreCase)
            {
                opts |= System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            }

            try
            {
                regEx = new System.Text.RegularExpressions.Regex(Pattern, opts);
            }
            catch (System.ArgumentException ex)
            {
                throw new System.ArgumentException("Invalid regular expression", ex);
            }
        }
Exemplo n.º 22
0
        public Regex(string pattern, System.Text.RegularExpressions.RegexOptions options)
        {
            int flags = 0;

            if ((options & System.Text.RegularExpressions.RegexOptions.CultureInvariant) != 0)
            {
                options &= ~System.Text.RegularExpressions.RegexOptions.CultureInvariant;
            }
            else
            {
                flags |= java.util.regex.Pattern.UNICODE_CASE
                         | java.util.regex.Pattern.CANON_EQ;
            }

            if ((options & System.Text.RegularExpressions.RegexOptions.IgnoreCase) != 0)
            {
                options &= ~System.Text.RegularExpressions.RegexOptions.IgnoreCase;
                flags   |= java.util.regex.Pattern.CASE_INSENSITIVE;
            }

            if ((options & System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace) != 0)
            {
                options &= ~System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace;
                flags   |= java.util.regex.Pattern.COMMENTS;
            }

            if ((options & System.Text.RegularExpressions.RegexOptions.Multiline) != 0)
            {
                options &= ~System.Text.RegularExpressions.RegexOptions.Multiline;
                flags   |= java.util.regex.Pattern.MULTILINE;
            }

            if ((options & System.Text.RegularExpressions.RegexOptions.Singleline) != 0)
            {
                options &= ~System.Text.RegularExpressions.RegexOptions.Singleline;
                flags   |= java.util.regex.Pattern.DOTALL;
            }

            options &= ~System.Text.RegularExpressions.RegexOptions.Compiled;
            if (options != 0)
            {
                throw new System.ArgumentOutOfRangeException();
            }

            JavaPattern = java.util.regex.Pattern.compile(pattern);
        }
Exemplo n.º 23
0
        public void Add(string rxPattern, CharacterSet first, int priority, bool caseInsensitive)
        {
            System.Text.RegularExpressions.RegexOptions options
                = System.Text.RegularExpressions.RegexOptions.CultureInvariant
                  | System.Text.RegularExpressions.RegexOptions.ExplicitCapture;

            if (caseInsensitive)
            {
                options |= System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            }

            if (String.IsNullOrEmpty(rxPattern))
            {
                throw new ArgumentNullException("rxPattern");
            }
            Add(new System.Text.RegularExpressions.Regex(rxPattern, options), first, priority);
        }
Exemplo n.º 24
0
        public static bool _Replace_System_String_System_String_System_String_System_Text_RegularExpressions_RegexOptions( )
        {
            //Parameters
            System.String input       = null;
            System.String pattern     = null;
            System.String replacement = null;
            System.Text.RegularExpressions.RegexOptions options = null;

            //ReturnType/Value
            System.String returnVal_Real        = null;
            System.String returnVal_Intercepted = null;

            //Exception
            Exception exception_Real        = null;
            Exception exception_Intercepted = null;

            InterceptionMaintenance.disableInterception( );

            try
            {
                returnValue_Real = System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement, options);
            }

            catch (Exception e)
            {
                exception_Real = e;
            }


            InterceptionMaintenance.enableInterception( );

            try
            {
                returnValue_Intercepted = System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement, options);
            }

            catch (Exception e)
            {
                exception_Intercepted = e;
            }


            Return((exception_Real.Messsage == exception_Intercepted.Message) && (returnValue_Real == returnValue_Intercepted));
        }
Exemplo n.º 25
0
        //Using Regex update the ModuleVersion
        private void RegexPlSql(string pFileName, Version version)
        {//any octet string in single quotes eg '1.2.3.4'
            System.Text.RegularExpressions.RegexOptions options   = System.Text.RegularExpressions.RegexOptions.Multiline;
            System.Text.RegularExpressions.Regex        reVersion = new System.Text.RegularExpressions.Regex(@"'(?<ver>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'", options);
            string s = "";

            System.Text.Encoding encoding = Helper.GetEncoding(pFileName);
            using (System.IO.StreamReader sr = new System.IO.StreamReader(pFileName))
            {
                s = @sr.ReadToEnd();
            }
            WriteVerbose(string.Format("The encoding used was {0}.", encoding));
            string replacement = string.Format("'{0}'", version.ToString());

            s = reVersion.Replace(@s, replacement);
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(pFileName, false, encoding))
            {
                sw.Write(s);
            }
        }
Exemplo n.º 26
0
        private void RegexToken(string pFileName, string key, string value)
        {
            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.Multiline;
            System.Text.RegularExpressions.Regex        reToken = new System.Text.RegularExpressions.Regex(@"(?<token>@(" + key + ")@)", options);
            string s = "";

            System.Text.Encoding encoding = Helper.GetEncoding(pFileName);
            using (System.IO.StreamReader sr = new System.IO.StreamReader(pFileName))
            {
                s = @sr.ReadToEnd();
            }
            WriteVerbose(string.Format("The encoding used was {0}.", encoding));

            string replacement = string.Format("{0}", value);

            s = reToken.Replace(@s, replacement);
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(pFileName, false, encoding))
            {
                sw.Write(s);
            }
        }
Exemplo n.º 27
0
        //Using Regex update the ModuleVersion
        //	ModuleVersion = '1.0.0.0'
        private void RegexVersionModule(string pFileName, Version version)
        {
            string s     = "";
            string regex = @"(?<mod>^\s*ModuleVersion\s*=\s*)(?<ver>('[0-9.]+'))";

            System.Text.Encoding encoding = Helper.GetEncoding(pFileName);
            using (System.IO.StreamReader sr = new System.IO.StreamReader(pFileName))
            {
                s = @sr.ReadToEnd();
            }
            WriteVerbose(string.Format("The encoding used was {0}.", encoding));

            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.Multiline;
            System.Text.RegularExpressions.Regex        re      = new System.Text.RegularExpressions.Regex(regex, options);
            string replacement = String.Format("${{mod}}'{0}'", version.ToString());

            s = re.Replace(@s, replacement);
            using (System.IO.StreamWriter sw = new System.IO.StreamWriter(pFileName, false, encoding))
            {
                sw.Write(s);
            }
        }
Exemplo n.º 28
0
        public static Regex ByPattern(string pattern, Option[] options)
        {
            if (pattern == null)
            {
                return(null);
            }

            if (options == null || !options.Any())
            {
                return(new Regex(pattern));
            }

            CSRegexOptions regexOptions = options.First().RegexOption;

            options = options.Skip(1).ToArray();

            foreach (var opt in options)
            {
                regexOptions |= opt.RegexOption;
            }

            return(new Regex(pattern, regexOptions));
        }
        // Group: Functions
        // __________________________________________________________________________


        /* Constructor: IgnoredSourceFolderPattern
         * Creates a new object from the passed pattern
         */
        public IgnoredSourceFolderPattern(string newPattern) : base(null)           // Set the regex later
        {
            string pattern = newPattern;

            pattern = System.Text.RegularExpressions.Regex.Replace(pattern, @"^\*?[/\\]", "");
            pattern = System.Text.RegularExpressions.Regex.Replace(pattern, @"[/\\]\*?$", "");
            pattern = System.Text.RegularExpressions.Regex.Replace(pattern, @"[/\\]", Engine.SystemInfo.PathSeparatorCharacter.ToString());

            pattern = System.Text.RegularExpressions.Regex.Escape(pattern);

            pattern = pattern.Replace("\\?", ".");
            pattern = pattern.Replace("\\*", ".*");
            pattern = @"(?:^|[/\\])" + pattern + @"(?:$|[/\\])";

            System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.Compiled;

            if (Engine.SystemInfo.IgnoreCaseInPaths)
            {
                options |= System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            }

            regex = new System.Text.RegularExpressions.Regex(pattern, options);
        }
Exemplo n.º 30
0
        /// <summary>
        /// 检查邮箱格式
        /// </summary>
        /// <param name="mail"></param>
        /// <returns></returns>
        private bool CheckIsMail(string mail)
        {
            string regexEmail = "\\w{1,}@\\w{1,}\\.\\w{1,}";

            System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace

                                                                    | System.Text.RegularExpressions.RegexOptions.Multiline)

                                                                   | System.Text.RegularExpressions.RegexOptions.IgnoreCase);

            System.Text.RegularExpressions.Regex regEmail = new System.Text.RegularExpressions.Regex(regexEmail, options);

            string email = mail;

            if (regEmail.IsMatch(email))
            {
                return(true);
            }
            else
            {
                resultInfo.messageText = "邮箱填写有误!";
                return(false);
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// 从指定的 HTML 文本中清除 HTML 标签和脚本标签“SCRIPT”等不可显示代码,只保留可显示文本。
        /// </summary>
        /// <param name="html">具有 HTML 格式的代码文本。</param>
        /// <returns>清除不可显示代码后的返回值。</returns>
        /// <example>
        /// <para lang="C#">
        /// 下面的代码演示了如何使用这个方法:
        /// </para>
        /// <code lang="C#">
        /// <![CDATA[this.Response.Write(RemoveHtmlLable(@"
        /// <table id=Table1 align=center border=0>
        /// <tr><TD>用户名</TD></tr>
        /// <TR><TD>密&nbsp;码</TD></TR>
        /// <TR><TD>验证码</TD></TR>
        /// </table>"));
        /// ]]>
        /// </code>
        /// <para lang="C#">
        /// 输出结果:
        /// <br/>用户名密 码验证码
        /// </para>
        /// </example>
        public static string RemoveHtmlLable(string html)
        {
            System.Text.RegularExpressions.RegexOptions regexOptions = System.Text.RegularExpressions.RegexOptions.ExplicitCapture | System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.IgnoreCase;

            string reHTML    = @"<HTML([^>]*)>|</HTML>";
            string reContain = @"<HEAD(?:[^>]*)>(?:.*?)</HEAD>|<STYLE(?:[^>]*)>(?:.*?)</STYLE>|<SCRIPT(?:[^>]*)>(?:.*?)</SCRIPT>";
            string reComment = @"<!--(.*?)-->";
            //string reBODY = @"<BODY(?:[^>]*)>|</BODY><TBODY(?:[^>]*)>|</TBODY>";
            //string reLable = @"<A(?:[^>]*)>|</A>|<SPAN(?:[^>]*)>|</SPAN>|<DIV(?:[^>]*)>|</DIV>|<FONT(?:[^>]*)>|</FONT>|<IMG(?:[^>]*)>|</IMG>|<TABLE(?:[^>]*)>|</TABLE>|<TR(?:[^>]*)>|</TR>|<TD(?:[^>]*)>|</TD>|<TBODY(?:[^>]*)>|</TBODY>";
            string reLable = @"<([^>]*)>";
            string reSpace = @"\s+";

            //string reOther = @"<(?:[^>]*)>|</(?:[^>]*)>";

            html = System.Text.RegularExpressions.Regex.Replace(html, reHTML, "", regexOptions);
            html = System.Text.RegularExpressions.Regex.Replace(html, reContain, "", regexOptions);
            html = System.Text.RegularExpressions.Regex.Replace(html, reComment, "", regexOptions);
            //html = System.Text.RegularExpressions.Regex.Replace( html, reBODY, "", regexOptions );
            html = System.Text.RegularExpressions.Regex.Replace(html, reLable, "", regexOptions);
            html = System.Text.RegularExpressions.Regex.Replace(html, reSpace, "", regexOptions);
            //html = System.Text.RegularExpressions.Regex.Replace( html, reOther, "", regexOptions );

            return(html);
        }