/// <summary> /// Do replace, show the result on replaced textbox. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void btnReplace_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtInput.Text)) { return; } if (string.IsNullOrEmpty(txtReplacement.Text)) { return; } //Match first btnMatch_Click(sender, e); UI2Data(); txtReplaceResult.Text = ruleItem.replaceText(txtInput.Text); HighLight hl = new HighLight(txtReplaceResult); hl.Reset2Default(); foreach (string result in ruleItem.Results) { string[] newV = Regex.Split(result, @"\t"); hl.Highlight(newV.Last()); } }
public void btnMatch_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(lblFilePath.Text)) { return; } try { hlFileContent.Reset2Default(); Dictionary <string, HtmlNodeCollection> kvNodes = HtmlParser.GetNodes(lblFilePath.Text, txtFilter.Text); treeResult.Nodes.Clear(); foreach (KeyValuePair <string, HtmlNodeCollection> kv in kvNodes) { TreeNode treeNode = treeResult.Nodes.Add(kv.Key, kv.Key); foreach (HtmlNode n1 in kv.Value) { ConvertHtmlNode(treeNode, n1); hlFileContent.Highlight(n1.StreamPosition, n1.OuterHtml.Length, Color.Black, Color.YellowGreen); } } if (!rules.Contains(txtFilter.Text)) { rules.Add(txtFilter.Text); listHistory.Items.Add(txtFilter.Text); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\n" + ex.StackTrace, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Do regex match, show the result on tree. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void btnMatch_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtInput.Text)) { return; } if (string.IsNullOrEmpty(txtPattern.Text)) { return; } HighLight hl = new HighLight(txtInput); hl.Reset2Default(); treeMatch.Nodes.Clear(); List <Match> matches = new List <Match>(); Regex reg = new Regex(txtPattern.Text, RegexOptions); matches.AddRange(reg.Matches(txtInput.Text).Cast <Match>()); BindMatchTree(matches, hl, reg, "Pattern"); if (!string.IsNullOrEmpty(txtRangeFrom.Text)) { Regex reg1 = new Regex(txtRangeFrom.Text, RegexOptions); matches.Clear(); matches.AddRange(reg1.Matches(txtInput.Text).Cast <Match>()); BindMatchTree(matches, hl, reg1, "RangeFrom", Color.Black, Color.LawnGreen); } if (!string.IsNullOrEmpty(txtRangeTo.Text)) { Regex reg1 = new Regex(txtRangeTo.Text, RegexOptions); matches.Clear(); matches.AddRange(reg1.Matches(txtInput.Text).Cast <Match>()); BindMatchTree(matches, hl, reg1, "RangeTo", Color.Black, Color.LawnGreen); } tabResult.SelectedTab = tpMatch; }