private void btnRegMatch_Click(object sender, EventArgs e) { string recordPath = AppDomain.CurrentDomain.BaseDirectory + "RegTestResult.txt"; string input = txtInput.Text; string pattern = txtPattern.Text; txtResult.Text = ""; MatchCollection matchCollection; try { matchCollection = Regex.Matches(input, pattern); foreach (Match match in matchCollection) { txtResult.Text += string.Format("匹配到的字符串是{0};", match.Value) + "\n"; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } //如果有记录,就将其写入文件 FileUtils.AppendAllText(recordPath, string.Format("{2}\r\n对字符串:\"{0}\"\r\n使用正则表达式:\"{1}\"的结果是" , input, pattern, DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss"))); if (matchCollection.Count > 0) { FileUtils.AppendAllText(recordPath, Regex.Split(txtResult.Text, @";").ToList()); } }
private void writeToFile(string saveFilePath, List <string> listContent) { if (cbxCoverageOrigin.Checked) { FileUtils.WriteAllLines(saveFilePath, listContent); } else { FileUtils.AppendAllText(saveFilePath, listContent); } }
private void TestMustUseCode() { string recordPath = AppDomain.CurrentDomain.BaseDirectory + "RegTestResult.txt"; string input = "ABCD\n\t123efgh 321ijk"; string pattern = @"\w."; txtInput.Text = input; txtPattern.Text = pattern; txtResult.Text = ""; MatchCollection matchCollection; try { matchCollection = Regex.Matches(input, pattern); foreach (Match match in matchCollection) { txtResult.Text += string.Format("匹配到的字符串是{0};", match.Value) + "\n"; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } //如果有记录,就将其写入文件 FileUtils.AppendAllText(recordPath, string.Format("{2}\r\n对字符串:\"{0}\"\r\n使用正则表达式:\"{1}\"的结果是" , input, pattern, DateTime.Now.ToString("yyyy-mm-dd hh:mm:ss"))); if (matchCollection.Count > 0) { FileUtils.AppendAllText(recordPath, Regex.Split(txtResult.Text, @";").ToList()); } //string input = "Warning" + '\u0007'; //string input2 = "a b111c d; b2222" + "aa\b" + "\\u008"; //string str1 = "Warning\u98989990007"; //MatchCollection matchCollect = new Regex("", RegexOptions.IgnoreCase).Matches(""); ////new Regex.Opt //string expr = @"\040b"; //Regex _regex = new Regex(""); ////MatchCollection _matchCollect = _regex.Matches(""); //MatchCollection _matchCollect = Regex.Matches(input, expr); //string[] strArray = Regex.Split(input, expr); }