12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Shapes;
- namespace Test.RegexTest
- {
- /// <summary>
- /// WinRegex.xaml 的交互逻辑
- /// </summary>
- public partial class WinRegex : Window
- {
- public WinRegex()
- {
- InitializeComponent();
- var s1 = System.IO.Path.GetPathRoot(@"c:\");
- var s2 = System.IO.Path.GetPathRoot(@"ccc");
- var flag1=System.IO.Path.IsPathRooted(@"c:\");
- var flag2=System.IO.Path.IsPathRooted(@".\ccc");
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- Output.Document.Blocks.Clear();
- var input = Input.Text;
- if (string.IsNullOrWhiteSpace(input))
- return;
- var regex = Regex.Text;
- if (string.IsNullOrWhiteSpace(regex))
- return;
- var match=System.Text.RegularExpressions.Regex.Match(input, regex);
- if (!match.Success)
- {
- WriteResult(false);
- return;
- }
- WriteValue(match.Value);
- for (int i = 0; i < match.Groups.Count; i++)
- {
- WriteGroup(i, match.Groups[i].ToString());
- }
- }
- private void WriteOutput(string str)
- {
- Output.AppendText(Environment.NewLine);
- Output.AppendText(str);
- }
- public void WriteResult(bool isSuccess)
- {
- WriteOutput(string.Format("Result:{0}", isSuccess.ToString()));
- }
- public void WriteValue(string value)
- {
- WriteOutput(string.Format("Value:{0}", value));
- }
- public void WriteGroup(int index, string val)
- {
- WriteOutput(string.Format("Group--{0}:{1}", index, val));
- }
- }
- }
|