正规则问题
如
1 attributeName="*"
2 attributename='*'
3 attributename=*
*任意多个字符,我想取attributeName的值.
取得的结果应为
1 *
2 *
3 *
它的正规则怎么写?
[解决办法]
"Attribute =(.*)"
[解决办法]
今天就结吧
string regexpress = string.Format("{0}\\s*=\\s*[\"']?(?<content>.+?)([\"']|$)", "Attribute"); //Attribute 填入你需要的属性名
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(regexpress);
string val = reg.Match(test1).Groups["content"].Value;
[解决办法]
^\"\w*\"|\'\w*\'|\w*$
测试一下
[解决办法]
这样就可以了
string rex = "\"+|'+";
Console.Write(regex.Replace(str, ""));
[解决办法]
string rex = "\"+ ¦'+";
Regex regex = new Regex(rex);
Console.Write(regex.Replace(str, ""));
把引号和分号全都换成空字符串
[解决办法]
var str="Attribute=id"
var aa=new RegExp("^Attribute=(.*)$");
var ss=str.match(aa)
[解决办法]
string[] test = new string[] { "attributeName=\"*\"", "attributename='*'", "attributename=*" };foreach (string s in test){ Match m = Regex.Match(s, @"attributeName=([""']?)(?<name>[^""'\s]*)\1", RegexOptions.IgnoreCase); if (m.Success) richTextBox1.Text += m.Groups["name"].Value + "\n";}