您的位置:程序门 -> .net技术 -> vb.net



80分  求一简单正则表达式


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


80分 求一简单正则表达式[已结贴,结贴人:fengkoulangjian]
发表于:2007-01-11 15:27:02 楼主
例如:

vx=3000m/s
ay=10...
hvx=300...

不管等号前面是什么,数字后面是什么,只取等号后面的数字部分,用正则怎么实现呢?
发表于:2007-01-11 15:36:451楼 得分:8
.*=(? <value> \d+)
发表于:2007-01-11 15:41:362楼 得分:8
dim   strregex   as   new   string( ".*=(? <value> \d+) ")
                dim   res   as   matchcollection   =   regex.matches(textbox1.text,   strregex)
                for   each   obj   as   match   in   res
                        messagebox.show(obj.groups(1).value)
                next
发表于:2007-01-11 15:53:373楼 得分:0
matchcollection     &     match     未定义,怎么办?高人
发表于:2007-01-11 15:55:154楼 得分:8
……
你问正则表达式,我当你会用了呢。要引用,在最前面写一句:
imports   system.text.regularexpressions
发表于:2007-01-11 16:07:145楼 得分:8
dim   str   as   string   =   "vx=3000m/s "
for   each   m   as   match   in   regex.matches(str,   "(? <=(?> [^=]+)=)\d+ ")
messagebox.show(m.value)
next
'凑个热闹
发表于:2007-01-11 17:22:416楼 得分:8
楼主没给分~
发表于:2007-01-11 17:29:177楼 得分:8
.*=(? <value> \d+)
发表于:2007-01-11 20:51:438楼 得分:8
(? <=.*=)\d+?
发表于:2007-01-11 20:57:329楼 得分:8
他们用于组捕,而且.*在前面会构成结果的一部分的。
可以试试我答案,使用match.nextmatch获得下一个结果,使用match.suess判断有没有下一个结果。
发表于:2007-01-12 08:30:2210楼 得分:8
"(? <=.*\s*=\s*)\d+ "

"\d+? "   100%错
发表于:2007-01-12 08:42:0211楼 得分:8
imports   system.text.regularexpressions;
//下面是c#语法。
string   yourstr   =   ......;
matchcollection   mc   =   regex.matches(yourstr,   "(? <=.+?\\s*=\\s*)\\d+ ",   regexoptions.ignorecase).value;
foreach(match   m   in   mc)
{
        m.value;//
}


快速检索

最新资讯
热门点击