当前位置:编程学习 > C#/ASP.NET >>

求简单正则

$str =1;$strx=2;$strd="a";
int a =10;


匹配所有 $xxx 就是前面的变量名字 不带$的不要 --------------------编程问答-------------------- --------------------编程问答-------------------- \b(\$\w*)\b --------------------编程问答-------------------- string pattern=@"\$\w+"; --------------------编程问答-------------------- --------------------编程问答-------------------- (?i)\$\w+\b --------------------编程问答-------------------- \$\w+\b --------------------编程问答-------------------- 大神们 我还想要 $xxx=xxx; 这个匹配啊 --------------------编程问答-------------------- --------------------编程问答-------------------- (\$[\w\s]*=[\w"]*) --------------------编程问答-------------------- \$\w+\b\s*=[^;]+; --------------------编程问答--------------------


//\$[^= ]+
var arr = '$str =1;$strx=2;$strd="a";'.match(/\$[^= ]+/ig);
for(var v=0;v<arr.length;v++)
{
alert(arr[v]);
}
}
--------------------编程问答-------------------- //正则表达式为:\$[a-zA-Z0-9="" ]+;

//测试结果为
 string s = @"$str =1;$strx=2;$strd=""a"";int a =10;";
            Regex reg = new Regex(@"\$[a-zA-Z0-9="" ]+;");
           MatchCollection matchs =  reg.Matches(s);

            foreach(Match m in matchs)
            {
                Console.WriteLine(m.Value);
            }

            Console.Read(); --------------------编程问答-------------------- 用10楼的吧
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,