日期:2014-05-17  浏览次数:20441 次

C# 正则表达式 一个字符串中获取连续的数字
比如字符串dsds dsds sdsdgfhh380 dsdskds765dsd
获取第一次出现的数字串
我要怎么写正则才能获取380呢?


在线等!急呀

------解决方案--------------------
C# code
        string str = "dsds dsds sdsdgfhh380 dsdskds765dsd";
        Regex reg = new Regex(@"\d+");
        Response.Write(reg.Match(str));

------解决方案--------------------
Regex regex = new Regex("\d+");
var m = regex.Match("dsds dsds sdsdgfhh380 dsdskds765dsd");
if (m.Success)
Console.WriteLine(m.Groups[0]);


------解决方案--------------------
探讨
Regex regex = new Regex("\d+");
var m = regex.Match("dsds dsds sdsdgfhh380 dsdskds765dsd");
if (m.Success)
Console.WriteLine(m.Groups[0]);

------解决方案--------------------
js

document.write(("dsds dsds sdsdgfhh380 dsdskds765dsd").match(/(\d)+/)[0]);
------解决方案--------------------
Regex.Match("","\\d+").Value
------解决方案--------------------
探讨

C# code
string str = "dsds dsds sdsdgfhh380 dsdskds765dsd";
Regex reg = new Regex(@"\d+");
Response.Write(reg.Match(str));