private void BindValues() { string sTo = emails; string regex = "([0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\\w]*[0-9a-zA-Z])*\\.)+[a-zA-Z]" + "{2,9})"; List <string> dic = new List <string>(); 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); foreach (Match item in reg.Matches(sTo)) { if (!dic.Contains(item.Value)) { dic.Add(item.Value); } } string[] _mas = dic.ToArray(); for (int i = 0; i < _mas.Length; i++) { lstSelected.Items.Add(new ListItem(_mas[i], _mas[i])); } Page.ClientScript.RegisterStartupScript(this.GetType(), "_startValues", "SaveFields();", true); }
public void ParseTemplate(string templateContent) { templateContent = PreprocessTemplate(templateContent); //使用正则表达式来列出模板中所有可能的数据标签 string regex = @"\$(\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 reg = new System.Text.RegularExpressions.Regex(regex, options); MatchCollection mc = reg.Matches(templateContent); foreach (Match m in mc) { if (m.Groups[1].Captures.Count > 0) { string tag = m.Groups[1].Value; StringCollection sc = DataLabels[tag] as StringCollection; if (sc == null) { sc = new StringCollection(); DataLabels[tag] = sc; } foreach (Capture c in m.Groups[2].Captures) { string field = c.Value; if (sc.IndexOf(field) < 0) { sc.Add(field); } } } } }
/// <summary> /// Build and return a Regex object from the current builder state. /// After calling this the builder is cleared and ready to re-use. /// </summary> /// <param name="options">Any number of regex options to apply to the regex</param> /// <returns>Regex as built</returns> public Regex BuildRegex(params RegexOptions[] options) { if (_openGroupCount == 1) { throw new RegexBuilderException("A group has been started but not ended", _stringBuilder); } if (_openGroupCount > 1) { throw new RegexBuilderException(_openGroupCount + " groups have been started but not ended", _stringBuilder); } System.Text.RegularExpressions.RegexOptions combinedOptions = System.Text.RegularExpressions.RegexOptions.None; foreach (var option in options) { switch (option) { case RegexOptions.IgnoreCase: combinedOptions |= System.Text.RegularExpressions.RegexOptions.IgnoreCase; break; case RegexOptions.Multiline: combinedOptions |= System.Text.RegularExpressions.RegexOptions.Multiline; break; } } var regex = new Regex(_stringBuilder.ToString(), combinedOptions); _stringBuilder.Clear(); return(regex); }
/// <summary> /// Expands links into HTML hyperlinks inside of text or HTML. /// </summary> /// <param name="text">The text to expand</param> /// <returns></returns> private string ExpandUrlsInternal(string text) { MatchEvaluator matchEval = null; string pattern = null; string updated = null; // Expand embedded hyperlinks System.Text.RegularExpressions.RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase; if (ParseFormattedLinks) { pattern = @"\[(.*?)\|(.*?)]"; matchEval = new MatchEvaluator(ExpandFormattedLinks); updated = Regex.Replace(text, pattern, matchEval, options); } else { updated = text; } pattern = @"([""'=]|")?(http://|ftp://|https://|www\.|ftp\.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])"; matchEval = new MatchEvaluator(ExpandUrlsRegExEvaluator); updated = Regex.Replace(updated, pattern, matchEval, options); return(updated); }
static bool Regex_Replace__String__String__MatchEvaluator__RegexOptions(JSVCall vc, int argc) { int len = argc; if (len == 4) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.String arg1 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.Text.RegularExpressions.MatchEvaluator arg2 = JSDataExchangeMgr.GetJSArg <System.Text.RegularExpressions.MatchEvaluator>(() => { if (JSApi.isFunctionS((int)JSApi.GetType.Arg)) { return(Regex_Replace_GetDelegate_member31_arg2(JSApi.getFunctionS((int)JSApi.GetType.Arg))); } else { return((System.Text.RegularExpressions.MatchEvaluator)JSMgr.datax.getObject((int)JSApi.GetType.Arg)); } }); System.Text.RegularExpressions.RegexOptions arg3 = (System.Text.RegularExpressions.RegexOptions)JSApi.getEnum((int)JSApi.GetType.Arg); JSApi.setStringS((int)JSApi.SetType.Rval, System.Text.RegularExpressions.Regex.Replace(arg0, arg1, arg2, arg3)); } return(true); }
/// <summary> /// Cleans a string from specific markup by converting it to its equivalent /// values in the environment. /// </summary> /// <param name="s"></param> /// <returns></returns> internal static string ReplaceHTMLMarkup(this string s) { // <BR> and <BR/> and <BR>\n -> new line // and + space -> space // < -> '<' // > -> '>' // & and && -> & // \n -> Environment.NewLine if (s == null) { return(null); } // Defines the options for replacement: ignore case and culture invariant. System.Text.RegularExpressions.RegexOptions ro = System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.CultureInvariant; StringComparison sc = StringComparison.InvariantCultureIgnoreCase; return(s .Replace("<BR/?>\n?", "\n", ro) .Replace("(?: ?)+", " ", ro) .Replace("<", "<", sc) .Replace(">", ">", sc) .Replace("(?:&)+", "&", ro) .Replace("\n", Environment.NewLine, sc)); }
void regExOptions_Change(PropertiesToolsWindowsProperty property) { RegexOptions regexOptions = new System.Text.RegularExpressions.RegexOptions(); // event retuens property with new value but we loop on all propertys to build regexOptions foreach (PropertiesToolsWindowsProperty propertyItem in regExPropertys.Propertys) { if (propertyItem.PropertyName == RegexOptions.IgnoreCase.ToString()) { if (propertyItem.PropertyValueTrueFalse == true) { regexOptions = regexOptions | RegexOptions.IgnoreCase; } } else if (propertyItem.PropertyName == RegexOptions.Multiline.ToString()) { if (propertyItem.PropertyValueTrueFalse == true) { regexOptions = regexOptions | RegexOptions.Multiline; } } else if (propertyItem.PropertyName == RegexOptions.Singleline.ToString()) { if (propertyItem.PropertyValueTrueFalse == true) { regexOptions = regexOptions | RegexOptions.Singleline; } } } regExParser.RegexOptions = regexOptions; // refresh textChange_KeyUp(null, null); }
/// <summary> /// 通用正则表达式判断函数 /// </summary> /// <param name="strVerifyString">String,用于匹配的字符串</param> /// <param name="strRegular">String,正则表达式</param> /// <param name="regOption">RegexOptions,配置正则表达式的选项</param> /// <param name="aryResult">ArrayList,分解的字符串内容</param> /// <param name="IsEntirety">Boolean,是否需要完全匹配</param> /// <returns></returns> public bool CommRegularMatch(string strVerifyString, string strRegular, System.Text.RegularExpressions.RegexOptions regOption, ref System.Collections.ArrayList aryResult, bool IsEntirety) { System.Text.RegularExpressions.Regex r; System.Text.RegularExpressions.Match m; #region 如果需要完全匹配的处理 if (IsEntirety) { strRegular = strRegular.Insert(0, @"\A"); strRegular = strRegular.Insert(strRegular.Length, @"\z"); } #endregion try { r = new System.Text.RegularExpressions.Regex(strRegular, regOption); } catch (System.Exception e) { throw (e); } for (m = r.Match(strVerifyString); m.Success; m = m.NextMatch()) { aryResult.Add(m); } if (aryResult.Count == 0) { return(false); } else { return(true); } }
void regExOptions_Change(PropertiesToolsWindowsProperty property) { RegexOptions regexOptions = new System.Text.RegularExpressions.RegexOptions(); // event retuens property with new value but we loop on all propertys to build regexOptions foreach (PropertiesToolsWindowsProperty propertyItem in regExPropertys.Propertys) { if (propertyItem.PropertyName == RegexOptions.IgnoreCase.ToString()) { if (propertyItem.PropertyValueTrueFalse == true) { regexOptions = regexOptions | RegexOptions.IgnoreCase; } } else if (propertyItem.PropertyName == RegexOptions.Multiline.ToString()) { if (propertyItem.PropertyValueTrueFalse == true) { regexOptions = regexOptions | RegexOptions.Multiline; } } else if (propertyItem.PropertyName == RegexOptions.Singleline.ToString()) { if (propertyItem.PropertyValueTrueFalse == true) { regexOptions = regexOptions | RegexOptions.Singleline; } } } regExParser.RegexOptions = regexOptions; // refresh textChange_KeyUp(null, null); }
public static string RegExMatchGroups(string pattern, string input, int Options) { if ((input == null || pattern == null)) { return(String.Empty); } System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions(); RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString()); int i = 0; foreach (Group group in Regex.Match(input, pattern, RegexOption).Groups) { if (!(i == 0)) { Console.WriteLine(group.Value); } i++; } //Console.WriteLine(Regex.Match(input, pattern, RegexOption).Groups); return(Regex.Match(input, pattern, RegexOption).Value); }
public RegexHunter(bool fMatchCase) { p_eSearchOptions = RegexOptions.Multiline; if (!fMatchCase) { p_eSearchOptions |= RegexOptions.IgnoreCase; } }
private string PreprocessTemplate(string templateContent) { //将公式定义单元格的内容清除 string regex0 = @" <td (?: (?:\s+(?!x:fmla)(?:\w+(?::\w+)?)(?:=(?:""[^""]*""|'[^']*'|\w*))?)* \s+x:fmla=(?:""[^""]*""|'[^']'|\w*) (?:\s+(?!x:fmla)(?:\w+(?:\:\w+)?)(?:=(?:""[^""]*""|'[^']*'|\w*))?)* )+ \s*> ( (?: <(?:(?!td)\w+)[^>]*> | </\s*(?:(?!td)\w+)\s*> | [^<]+ )* ) </\s*td\s*>"; System.Text.RegularExpressions.RegexOptions options0 = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline) | System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex reg0 = new System.Text.RegularExpressions.Regex(regex0, options0); templateContent = reg0.Replace(templateContent, new MatchEvaluator(this.ClearFormulaValue)); //清除数据标签中的嵌入HTML标签,因为写成一个正则表达式对某些文档会倒致正则表达式分析死锁,我们将它分成若干个层次来处理 //找出<td></td>中以$开头以$结尾的模式,在$与$之间有可能有<td></td>,在开始<td>与第一个$间只有非<td></td>HTML标签与 //在第二个$与结束</td>之间也只有非<td></td>HTML标签与 string regex = @" <td[^>]*> ( (?: (?:</\s*(?:(?!td)\w+)\s*>) | \s* \s* )* ) ( \$[^\$]+ ) ( \$ (?: <(?:(?!td)\w+)[^>]*> | (?:</\s*(?:(?!td)\w+)\s*>) | \s* \s* )* ) </\s*td\s*>"; 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.Replace(templateContent, new MatchEvaluator(this.RemoveHtmlTag))); }
public string RegexReplace(string input, string pattern, string replacement, bool ignoreCase) { System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.Compiled | System.Text.RegularExpressions.RegexOptions.CultureInvariant; if (ignoreCase) { options |= System.Text.RegularExpressions.RegexOptions.IgnoreCase; } return(System.Text.RegularExpressions.Regex.Replace(input, pattern, replacement, options)); }
public static SqlString RegExReplacex(SqlString pattern, SqlString input, SqlString replacement, SqlInt32 Options) { if ((input.IsNull || pattern.IsNull)) { return(SqlString.Null); } System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions(); //RegexOption = Options; RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString()); return(new SqlString(Regex.Replace(input.Value, pattern.Value, replacement.Value, RegexOption))); }
public static bool ValidateEmail(string email) { string regex = @"^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&\'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$"; 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); Match m = reg.Match(email); return(m.Success); }
public static string TidyHtml(string html) { TidyNet.Tidy tidy = new TidyNet.Tidy(); /* Set the options you want */ tidy.Options.DocType = TidyNet.DocType.Strict; tidy.Options.DropFontTags = true; tidy.Options.LogicalEmphasis = true; if (GlobalSettings.EditXhtmlMode == "true") { tidy.Options.Xhtml = true; tidy.Options.XmlOut = true; } else { tidy.Options.XmlOut = false; tidy.Options.Xhtml = false; } tidy.Options.MakeClean = true; tidy.Options.TidyMark = false; // To avoid entity encoding tidy.Options.CharEncoding = (TidyNet.CharEncoding)Enum.Parse(typeof(TidyNet.CharEncoding), UmbracoSettings.TidyCharEncoding); /* Declare the parameters that is needed */ TidyNet.TidyMessageCollection tmc = new TidyNet.TidyMessageCollection(); MemoryStream input = new MemoryStream(); MemoryStream output = new MemoryStream(); byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(html); input.Write(byteArray, 0, byteArray.Length); input.Position = 0; tidy.Parse(input, output, tmc); string tidyed = System.Text.Encoding.UTF8.GetString(output.ToArray()); // only return body string regex = @"</{0,1}body[^>]*>"; 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); string[] s = reg.Split(tidyed); if (s.Length > 1) { return(s[1]); } else { return("[tidy error]"); } }
public static IEnumerable RegExMatches(SqlString pattern, SqlString input, SqlInt32 Options) { if ((input.IsNull || pattern.IsNull)) { return(null); } System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions(); //RegexOption = Options; RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString()); return(Regex.Matches(input.Value, pattern.Value, RegexOption)); }
public static SqlString RegExMatch(SqlString pattern, SqlString input, SqlInt32 Options) { if ((input.IsNull || pattern.IsNull)) { return(String.Empty); } System.Text.RegularExpressions.RegexOptions RegexOption = new System.Text.RegularExpressions.RegexOptions(); //RegexOption = (int)Options; RegexOption = (RegexOptions)Enum.Parse(typeof(RegexOptions), Options.ToString()); return(Regex.Match(input.Value, pattern.Value, RegexOption).Value); }
private void CreateMatcher() { if (null == m_obRegex) { System.Text.RegularExpressions.RegexOptions options = System.Text.RegularExpressions.RegexOptions.Singleline; if (!m_bCaseSensitive) { options |= System.Text.RegularExpressions.RegexOptions.IgnoreCase; } m_obRegex = new Regex(m_strValuePattern, options); } }
static bool Regex_IsMatch__String__String__RegexOptions(JSVCall vc, int argc) { int len = argc; if (len == 3) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.String arg1 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.Text.RegularExpressions.RegexOptions arg2 = (System.Text.RegularExpressions.RegexOptions)JSApi.getEnum((int)JSApi.GetType.Arg); JSApi.setBooleanS((int)JSApi.SetType.Rval, (System.Boolean)(System.Text.RegularExpressions.Regex.IsMatch(arg0, arg1, arg2))); } return(true); }
static bool Regex_Matches__String__String__RegexOptions(JSVCall vc, int argc) { int len = argc; if (len == 3) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.String arg1 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.Text.RegularExpressions.RegexOptions arg2 = (System.Text.RegularExpressions.RegexOptions)JSApi.getEnum((int)JSApi.GetType.Arg); JSMgr.datax.setObject((int)JSApi.SetType.Rval, System.Text.RegularExpressions.Regex.Matches(arg0, arg1, arg2)); } return(true); }
static bool Regex_Replace__String__String__String__RegexOptions(JSVCall vc, int argc) { int len = argc; if (len == 4) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.String arg1 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.String arg2 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.Text.RegularExpressions.RegexOptions arg3 = (System.Text.RegularExpressions.RegexOptions)JSApi.getEnum((int)JSApi.GetType.Arg); JSApi.setStringS((int)JSApi.SetType.Rval, System.Text.RegularExpressions.Regex.Replace(arg0, arg1, arg2, arg3)); } return(true); }
private void SetOption(bool value, RegExp.RegexOptions option) { var options = _regex.Options; if (value) { options |= option; } else { options &= ~option; } //приходится пересоздавать объект, т.к. опции объекта по умолчанию только read-only _regex = new RegExp.Regex(_pattern, options); }
private static string[] SplitString(string inputString) { System.Text.RegularExpressions.RegexOptions options = ((System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace | System.Text.RegularExpressions.RegexOptions.Multiline) | System.Text.RegularExpressions.RegexOptions.IgnoreCase); Regex reg = new Regex("(?:^|,)(\\\"(?:[^\\\"]+|\\\"\\\")*\\\"|[^,]*)", options); MatchCollection coll = reg.Matches(inputString); string[] items = new string[coll.Count]; int i = 0; foreach (Match m in coll) { items[i++] = m.Groups[0].Value.Trim('"').Trim(',').Trim('"').Trim(); } return(items); }
/// <summary> /// Expands links into HTML hyperlinks inside of text or HTML. /// </summary> /// <param name="Text">The text to expand</param> /// <param name="Target">Target frame where output is displayed</param> /// <returns></returns> public string ExpandUrls(string Text) { string pattern = @"([""'=]|")?(http://|ftp://|https://|www\.|ftp\.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])"; //string pattern = @"[""'=]?(http://|ftp://|https:/[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])|((www\.)|(ftp\.)).*?((\.com)|(\.net)|(\.org))((.|\?|\#)+\s)?"; //string pattern = @"[""'=]?(http://|ftp://|https://|mailto:)[\w]+(.[\w]+)([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])|((www\.)|(ftp\.)).*?((\.com)|(\.net)|(\.org))"; // *** Expand embedded hyperlinks System.Text.RegularExpressions.RegexOptions options = RegexOptions.Multiline | RegexOptions.IgnoreCase; MatchEvaluator MatchEval = new MatchEvaluator(this.ExpandUrlsRegExEvaluator); return(Regex.Replace(Text, pattern, MatchEval, options)); }
public static string BootstrapTidy(string html) { string emptyTags = ",br,hr,input,img,"; string regex = "(<[^\\?][^(>| )]*>)|<([^\\?][^(>| )]*)([^>]*)>"; Hashtable replaceTag = new Hashtable(); replaceTag.Add("strong", "b"); replaceTag.Add("em", "i"); 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); foreach (Match m in reg.Matches(html)) { string orgTag = ""; string tag = ""; string cleanTag = ""; if (m.Groups.Count < 2 || (m.Groups[2].Value.ToLower() != "img" || (m.Groups[2].Value.ToLower() == "img" && m.Value.IndexOf("?UMBRACO_MACRO") == -1))) { if (m.Groups[1].Value != "") { orgTag = m.Groups[1].Value; cleanTag = replaceTags(m.Groups[1].Value.ToLower().Replace("<", "").Replace("/>", "").Replace(">", "").Trim(), replaceTag); tag = "<" + cleanTag + ">"; } else { orgTag = "<" + m.Groups[2].Value + m.Groups[3].Value + ">"; // loop through the attributes and make them lowercase cleanTag = replaceTags(m.Groups[2].Value.ToLower(), replaceTag); tag = "<" + cleanTag + returnLowerCaseAttributes(m.Groups[3].Value) + ">"; } // Check for empty tags if (bool.Parse(GlobalSettings.EditXhtmlMode) && emptyTags.IndexOf("," + cleanTag + ",") > -1 && tag.IndexOf("/>") == -1) { tag = tag.Replace(">", " />"); } html = html.Replace(orgTag, tag); } } return(html); }
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); }
static bool Regex_Regex2(JSVCall vc, int argc) { int _this = JSApi.getObject((int)JSApi.GetType.Arg); JSApi.attachFinalizerObject(_this); --argc; int len = argc; if (len == 2) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.Text.RegularExpressions.RegexOptions arg1 = (System.Text.RegularExpressions.RegexOptions)JSApi.getEnum((int)JSApi.GetType.Arg); JSMgr.addJSCSRel(_this, new System.Text.RegularExpressions.Regex(arg0, arg1)); } return(true); }
static string sqlNormalize(string normalQuery) { string returnValue = normalQuery; //Find /* secuence and remove string regex = "^(?<BlockComment>/\\*.*\\*/)|(?<LinealComment>--.*)$"; 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); Match mat = reg.Match(normalQuery); //returnValue = Regex.Replace(normalQuery, regex,"$´$'",options); returnValue = returnValue.Replace(Environment.NewLine, " "); returnValue = returnValue.Replace("\t", " "); returnValue = reg.Replace(returnValue, "$´$'"); return(returnValue); }
static bool Regex_Split__String__String__RegexOptions(JSVCall vc, int argc) { int len = argc; if (len == 3) { System.String arg0 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.String arg1 = (System.String)JSApi.getStringS((int)JSApi.GetType.Arg); System.Text.RegularExpressions.RegexOptions arg2 = (System.Text.RegularExpressions.RegexOptions)JSApi.getEnum((int)JSApi.GetType.Arg); var arrRet = System.Text.RegularExpressions.Regex.Split(arg0, arg1, arg2); for (int i = 0; arrRet != null && i < arrRet.Length; i++) { JSApi.setStringS((int)JSApi.SetType.SaveAndTempTrace, arrRet[i]); JSApi.moveSaveID2Arr(i); } JSApi.setArrayS((int)JSApi.SetType.Rval, (arrRet != null ? arrRet.Length : 0), true); } return(true); }
public static string GetInlineFlags(this System.Text.RegularExpressions.RegexOptions options) { string flags = string.Empty; if (options.HasFlag(RegexOptions.IgnoreCase)) { flags += "i"; } if (options.HasFlag(RegexOptions.Singleline)) { flags += "s"; } if (options.HasFlag(RegexOptions.Multiline)) { flags += "m"; } if ((options & ~(RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Multiline)) != 0) { throw new ArgumentException("Unsupported RegularExpression flags"); } return(flags); }
private void RunRegex() { string regex_output_text; iregexoptions = RegexOptions.None; System.Text.RegularExpressions.Regex thisregex; //Replace any \t with actual tabs in replace expression //regex_replace = Regex.Replace(regex_replace, @"[^\\]?\\t", "\t"); regex_replace = regex_replace.Replace("\\t", "\t"); // replace \t with a tab regex_replace = regex_replace.Replace("\\\t", "\\t"); // restore \[tab] with \\t //regex_replace = Regex.Replace(regex_replace, @"[^\\]?\\n", "\n"); regex_replace = regex_replace.Replace("\\n", "\n"); regex_replace = regex_replace.Replace("\\\n", "\\n"); //regex_replace = Regex.Replace(regex_replace, @"[^\\]?\\r", "\r"); regex_replace = regex_replace.Replace("\\r", "\r"); regex_replace = regex_replace.Replace("\\\r", "\\r"); regex_replace = Regex.Replace(regex_replace, @"[^\\]?\\d", System.DateTime.Now.ToShortDateString()); //regex_replace = regex_replace.Replace("\\d", "\n"); //regex_replace = regex_replace.Replace("\\\n", "\\n"); regex_match = regex_match.Replace("\\t", "\t"); // replace \t with a tab regex_match = regex_match.Replace("\\\t", "\\t"); // restore \[tab] with \\t //regex_replace = Regex.Replace(regex_replace, @"[^\\]?\\n", "\n"); regex_match = regex_match.Replace("\\n", "\n"); regex_match = regex_match.Replace("\\\n", "\\n"); regex_match = regex_match.Replace("$^", "$\n^"); //regex_replace = Regex.Replace(regex_replace, @"[^\\]?\\r", "\r"); regex_match = regex_match.Replace("\\r", ""); // \r is removed through end of line normalization //regex_match = regex_match.Replace("\\\r", "\\r"); if(regex_checkbox_multiLine) { iregexoptions |= System.Text.RegularExpressions.RegexOptions.Multiline; } if(regex_checkBox_singleline) { iregexoptions |= System.Text.RegularExpressions.RegexOptions.Singleline; } try { thisregex = new System.Text.RegularExpressions.Regex(regex_match, (casesensitive ? 0 : System.Text.RegularExpressions.RegexOptions.IgnoreCase ) | iregexoptions); } catch (System.Exception ex) { OnMessageEvent("output", "EXCEPTION:" + ex.Message); RegexFinished.BeginInvoke(this, System.EventArgs.Empty, null, null); return ; } //The Actual regular expression OnMessageEvent("label", ""); //clear status if(!regex_match_mode) { int i_hash = input_text.GetHashCode(); input_text = input_text.Replace("\r", ""); //Normalize CRLFs // Run the user-entered regex and normalize LF's back to CRLFs try { regex_output_text = thisregex.Replace(input_text, regex_replace).Replace("\n", "\r\n"); } catch (Exception ex) { OnMessageEvent("output", "EXCEPTION:" + ex.Message); RegexFinished.BeginInvoke(this, System.EventArgs.Empty, null, null); return ; } //HANDLE THE \l operator int lpos = 0; while(regex_output_text.IndexOf(@"\l") != -1) { lpos = regex_output_text.IndexOf(@"\l"); regex_output_text = regex_output_text.Substring(0, lpos) + regex_output_text.Substring(lpos + 2, 1).ToLower() + regex_output_text.Substring(lpos + 3); } var o_hash = regex_output_text.GetHashCode(); if(i_hash == o_hash) OnMessageEvent("label", "No occurances found."); OnMessageEvent("output", regex_output_text); RegexFinished.Invoke(this, System.EventArgs.Empty); } else { // Output contains only matches : ignore the rest input_text = input_text.Replace("\r", ""); System.Text.StringBuilder tempstring = new System.Text.StringBuilder(); // output_textbox.Text = ""; System.Text.RegularExpressions.MatchCollection mymatches = thisregex.Matches(input_text); if(mymatches.Count == 0) { OnMessageEvent("label", "No occurances found."); /*output_textbox.Text = "";*/ } string backupreplace; int icounter = 0; // Initializes the incrementing counter with starting value in replace expression if(System.Text.RegularExpressions.Regex.Match(regex_replace, @"\\i\d+").Success) { icounter = Convert.ToInt32(System.Text.RegularExpressions.Regex.Match(regex_replace, @"\\i(\d+)").Groups[1].Value); regex_replace = System.Text.RegularExpressions.Regex.Replace(regex_replace, @"\\i\d+", @"\i"); //remove initial value } string matchvalue = ""; System.Collections.Generic.List<string> previousmatches = new List<string>(mymatches.Count); try { for (int i = 0; i < mymatches.Count; i++) { matchvalue = mymatches[i].Value; if (ignoreduplicates && previousmatches.Contains(matchvalue)) { continue; } if (regex_replace.Length == 0) //If they didn't provide a replace expression, then output the matches tempstring.Append(matchvalue + "\r\n"); else { if (regex_replace.IndexOf(@"\i") != -1) { // System.Windows.Forms.MessageBox.Show("found a number" + icounter.ToString()); backupreplace = regex_replace; regex_replace = regex_replace.Replace(@"\i", icounter.ToString()); icounter++; tempstring.Append(System.Text.RegularExpressions.Regex.Replace(matchvalue, regex_match, regex_replace, System.Text.RegularExpressions.RegexOptions.IgnoreCase | iregexoptions)); regex_replace = backupreplace; } else { tempstring.Append(System.Text.RegularExpressions.Regex.Replace(matchvalue, regex_match, regex_replace, System.Text.RegularExpressions.RegexOptions.IgnoreCase | iregexoptions)); } } previousmatches.Add(matchvalue); } OnMessageEvent("output", tempstring.ToString().Replace("\n", "\r\n")); } catch (System.Exception ex) { OnMessageEvent("output", "EXCEPTION:" + ex.Message); } //output_textbox.Text = tempstring.ToString().Replace("\n", "\r\n"); } //Perform line terminator massaging RegexFinished.BeginInvoke(this, System.EventArgs.Empty, null, null); return ; }