2 回答
![?](http://img1.sycdn.imooc.com/533e4d660001312002000200-100-100.jpg)
TA贡献1820条经验 获得超9个赞
static void Main(string[] args){
Regex rx = new Regex(@"\[Ref:(-?[0-9]+)/(-?[0-9]+)/(-?[0-9]+)\]");
string text = "This is a string [Ref:1234/823/2]";
MatchCollection matches = rx.Matches(text);
foreach (Match match in matches)
{
GroupCollection groups = match.Groups;
int first_value = Int32.Parse(groups[1].Value);
int second_value = Int32.Parse(groups[2].Value);
int third_value = Int32.Parse(groups[3].Value);
}
}
(编辑)如果您不需要这些值:
static void Main(string[] args){
Regex rx = new Regex(@"\[Ref:(-?[0-9]+)/(-?[0-9]+)/(-?[0-9]+)\]");
string text = "This is a string [Ref:1234/823/2]";
bool matched = rx.IsMatch(text);
}
- 2 回答
- 0 关注
- 157 浏览
添加回答
举报