如何用正则表达式匹配出变量
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
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
相关文章推荐
- 如何在php中用正则表达式匹配utf-8…
- 如何理解正则表达式匹配过程
- 路径变量中使用正则表达式匹配
- 如何用正则表达式匹配HTML中的动态数据?
- 如何用正则表达式匹配包括换行符的任意字符?
- 如何让正则表达式最小匹配
- 正则表达式要匹配双引号"如何才能匹配
- php中utf-8编码下用正则表达式如何匹配汉字
- php中utf-8编码下用正则表达式如何匹配汉字
- 正则表达式--模式匹配--特殊变量(1)
- 正则表达式--模式匹配--特殊变量(2)
- 含有换行符的正则表达式如何匹配
- python中如何用正则表达式匹配汉字
- 正则表达式如何匹配正反斜杠
- [小知识] grep中如何使用正则表达式匹配数字
- 非贪婪匹配:如何使用正则表达式碰到到第一个匹配到的字符串就停止
- php中utf-8编码下用正则表达式如何匹配汉字
- 含有换行符的正则表达式如何匹配
- UTF-8正则表达式如何匹配汉字
- php正则表达式如何找到匹配模式中的最后一组