您的位置:首页 > 其它

如何用正则表达式匹配出变量

2009-08-09 12:42 337 查看
如果想匹配"y|abc|" 中的abc,如何匹配呢?下面就是方法:

System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"^/|y/|(?<name>/w+)/|$");

string str = "|y|abc|";
if (regex.IsMatch(str))
{
MessageBox.Show(regex.Match(str).Groups["name"].Value.ToString());
}
输出:abc
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: