我爱Aspx >> Asp.Net >> 全面剖析C#正则表达式Match方法是在输入字符串中搜索正则表达式的匹配项,并Regex 类的 Match 方法返回 Match 对象,Match 类表示正则表达式匹配操作的结果。下面的例子演示Match方法的使用,并利用Match对象的Group属性返回Group对象:
string text = @"public string testMatchObj string s string match ";
string pat = @"(\w+)\s+(string)";
// Compile the regular expression.
Regex r = new Regex(pat, RegexOptions.IgnoreCase);
// Match the regular expression pattern against a text string.
Match m = r.Match(text);
int matchCount = 0;
while (m.Success)
{
Response.Write("Match"+ (++matchCount) + "<br>");
for (int i = 1; i <= 2; i++)
{
Group g = m.Groups[i];
Response.Write("Group"+i+"='" + g + "'" + "<br>");
CaptureCollection cc = g.Captures;
for (int j = 0; j < cc.Count; j++)
{
Ҷƪл˵?
C#里面全角和半角的自由转换[05-20]
C#操作注册表[05-20]
最简单的字符串加密C#实现-移位..[05-20]
C#中字符串的加密[05-20]
用C#获取硬盘序列号,CPU序列号,网..[05-20]
c#如何获得cpu,硬盘的物理序列号[05-20]
使用C#实现阿拉伯数字到大写中文..[05-20]
C#(IsNumeric) 字符串转换为数字..[05-20]
深入理解C#编程中的组件-事件-委..[05-20]
C#中一些字符串操作的常用用法[05-20]
正则表达式语法[05-20]
JScript 和 VBScript 正则表达式..[05-20]
正则表达式基础知识[05-20]
TAPI (Telephony application pr..[05-20]
C#里面全角和半角的自由转换[05-20]
C#操作注册表[05-20]
最简单的字符串加密C#实现-移位..[05-20]
C#中字符串的加密[05-20]
用C#获取硬盘序列号,CPU序列号,网..[05-20]
c#如何获得cpu,硬盘的物理序列号[05-20]