有以下这么一段文本_text,我需要分解成为这样一个东西: this hyButton4 ResourceID frmResEditor_hyButton4四个匹配项,请问如何写这个正则表达式?
string _text = "this.hyButton4.ResourceID = \"frmResEditor_hyButton4\";";
string _text = "this.hyButton4.ResourceID = \"frmResEditor_hyButton4\";";
解决方案 »
- 怎么判断选中了dataGridView的列标题行
- winform多线程问题
- GridView中BoundField列中的值如何获取?请进~急!
- 问一个白痴问题:如何将一个UserControl或者Class生成DLL文件
- ListView问题?
- 关于在winform中如何操作word 从列表中打开选定的word,修改后,再保存到服务器上
- 这个语句应怎么写呢
- 文本空格和换行的问题
- 产生异常后更新执行成功?
- 使用C#调用C++编写的dll库的效率如何?
- 如何双击一个DataGrid中的一行,将其添加到另一个DataGrid中?
- 今天在线等,马上给分用多个text控件用来计算,实现不填值就是空,用-来表示,有值的就计算。
//正则表达式:^([^\s]+)\s*\.\s*([^\s]+)\s*\.\s*([^\s]+)\s*=\s*"([^"]+)"\s*;$string _text = "this.hyButton4.ResourceID = \"frmResEditor_hyButton4\";";
Regex re = new Regex(@"^([^\s]+)\s*\.\s*([^\s]+)\s*\.\s*([^\s]+)\s*=\s*""([^""]+)""\s*;$");
Match m = re.Match(_text);
//分别获取四个匹配项
//m.Groups[1].Value
//m.Groups[2].Value
//m.Groups[3].Value
//m.Groups[4].Value
static void Main()
{
string str = "string _text = 'this.hyButton4.ResourceID = \"frmResEditor_hyButton4\";';";
string value = str.Substring(str.IndexOf("'"));
string[] strs = Regex.Split(value, @"[^\d|^\w]");
string[] strsReturn = new string[4];
int i = 0;
foreach (string s in strs)
{
if(! (s.Trim().Equals("")))
{
strsReturn[i] = s;
i++;
}
}
foreach (string s in strsReturn)
{
Console.WriteLine(s);
}
Console.ReadKey();
}
"[(this)|(hyButton4)|(ResourceID)|(frmResEditor_hyButton4)]+"
"this.(?<ctrlname>[^.].*?)\\.(?<ctrltype>[ResourceID|Text|Name].*?)\\s=\\s\"(?<ctrltext>[^\"].*?)\"$";散分。