/// <summary> /// <para>Initializes the data</para> /// </summary> private async void InitData() { // Lock RegexGroupsCollection BindingOperations.EnableCollectionSynchronization(RegexGroupsCollection, _regexGroupsCollectionLock); // call for RegexHander.LoadData with the regex we want to search and the file int res = await RegexHandler.LoadData(RegularExpressionString, FileLocation); // if the returned result is "0" than all ok and we should update the TextBox text. if (res == 0) { TextBoxTextCollection = RegexHandler.FullTextCollection; ComboBoxSelectedIndex = 0; } // otherwise there were no matches else if (res == 1) { TextBoxTextCollection = new ObservableCollection <string> { "Sorry, nothing matched" }; } else if (res == 2) { TextBoxTextCollection = new ObservableCollection <string> { "Invalid Regular expression" }; } }
/// <summary> /// Searches through files being fed to the StreamReader and adds them to the Dictionary if they match the pattern for reagents being created. /// </summary> /// <param name="reagentName">The reagent being searched for.</param> /// <param name="sr">The StreamReader going through the files.</param> protected void DoLines(string reagentName, StreamReader sr) { string line; while ((line = sr.ReadLine()) != null) { line = FileAccessing.HtmlToPlainText(line); if (RegexHandler.MatchFilter(line, RegexPatterns.Reagent(reagentName))) { _name = RegexHandler.MatchCkey(line); //_name = MatchString(line, patternName).ToLower(); //match name _dose = RegexHandler.MatchDose(line); //_dose = MatchString(line, patternDose); //match reagent dose //add to dic if (Int32.TryParse(_dose, out int doseInt)) { if (!_ckeyDic.ContainsKey(_name)) { _ckeyDic.Add(_name, doseInt); } else { _ckeyDic[_name] = _ckeyDic[_name] + doseInt; } } } } }
private static List <string> GetSqlParmListWithContent(string sqlContent) { var retList = RegexHandler.GetAllMatchList(sqlContent, "\\:[\\w]*"); return(retList.Select(ret => ret.Replace(":", "").ToUpper()).ToList()); }
public NextCommand(RegexHandler regexHandler) { _regexHandler = regexHandler; }
public PreviousCommand(RegexHandler regexHandler) { _regexHandler = regexHandler; }
private static string RegexReplace(Regex regex, RegexHandler handler, string input) { int lastIndex = 0; StringBuilder sb = new StringBuilder(input.Length * 2); Match match = regex.Match(input); while (match.Success && (lastIndex < input.Length)) { // Copy the skipped part. sb.Append(input.Substring(lastIndex, match.Index - lastIndex)); // Handle the match. string text = handler(match); // Either copy a replacement or the matched part as-is. sb.Append(text ?? match.Value); lastIndex = match.Index + match.Length; match = match.NextMatch(); } // Copy the remaining bit. if (lastIndex == 0) { // There were no matches. Debug.Assert(sb.Length == 0, "Expected no matches."); return input; } sb.Append(input.Substring(lastIndex)); return sb.ToString(); }
protected void MatchRegex(string regex, RegexHandler handler, RegexOptions options = RegexOptions.None) { RegexHandlers.Add(new Regex(regex, RegexOptions.Compiled | options), handler); }