请教正则表达问题,取两个字符中间部分,等待 Regex re=new Regex(@"\:([^<]+)\<"); Match.Groups[0]即是:apple<Match.Groups[1]即是apple想取得":"后面所有的字符\:([^\:]+) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 谢谢,xinbuzailiulei能给我解释一下,这里的groups[0]和groups[1]是怎么回事呢如果下面的取得一行的,又是什么呢 string str=@"item:apple <fruit> charater:shine isuooiuiduigudifuod";//取出的是 :和 < 之间的部分System.Text.RegularExpressions.Regex re=new System.Text.RegularExpressions.Regex(@".*\:(.*)<.*");str = re.Replace(str, "$1", -1);//如果取":"后面所有的字符,将表达式写成".*?\:(.*)$" groups[0]是匹配的整个字符串,groups[1]....groups[n]则是依次匹配的自字符串string str=@"item:apple <fruit> charater:shine isuooiuiduigudifuod"; Regex re=new Regex(@"\:([^<]+)\<"); Match oMatch=re.Match(str); string oStr=""; if(oMatch.Success==true){ GroupCollection oGC=oMatch.Groups; oStr+=oGC[0].Value+"\n";//整个匹配字符串 oStr+=oGC[1].Value+"\n";//第一个子匹配 MessageBox.Show(oStr); } re=new Regex(@"\:([^\:]+)"); oMatch=re.Match(str); oStr=""; while(oMatch.Success==true) { GroupCollection oGC=oMatch.Groups; //oStr+=oGC[0].Value+"\n";//整个匹配字符串 oStr+=oGC[1].Value+"\n";//第一个子匹配 oMatch=oMatch.NextMatch(); } MessageBox.Show(oStr); 继续感谢还有个问题想一并问了,就是这样一个字符串"?sjdoufdi=====?="我想取出?和?=之间的所有内容Regex re=new Regex(@"?([^?]+)?=); //因为字符串中间可能出现单独的?或者是=但是不会出现?=我这样写得到的结果只是出现一个=的时候就结束了,这是为什么对上面的那个字符串得到的结果是 sjdoufdi=如果字符串是 "?sa=sjou=ldjouifdidofi?=" 得到的是sa=请教怎样才能得到我想要的结果 string str="?sjdoufdi=====?="; Regex re=new Regex(@"\?([^\?]+)\?\="); Match oMatch=re.Match(str); string oStr=""; if(oMatch.Success==true){ GroupCollection oGC=oMatch.Groups; oStr+=oGC[0].Value+"\n"; oStr+=oGC[1].Value+"\n"; MessageBox.Show(oStr); } ADODB.Stream 中文乱码问题 请教关于WPF的问题,大侠帮忙啊 前台<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查询" />里边传个参数 vs.net2005设置的断点无效,不能调试 数据库连接问题 如何设置owc生成的图片中的文字大小? 请教.NET如何与MapGis一起使用 严重迫切的一个问题! .net转 SAP开发,大家觉得如何 我想做一个客户端和服务器之间通信的程序,请大家帮帮我,散分! 解决不了急啊 字符串如何转化为时间
System.Text.RegularExpressions.Regex re=new System.Text.RegularExpressions.Regex(@".*\:(.*)<.*");
str = re.Replace(str, "$1", -1);//如果取":"后面所有的字符,将表达式写成".*?\:(.*)$"
Regex re=new Regex(@"\:([^<]+)\<");
Match oMatch=re.Match(str);
string oStr="";
if(oMatch.Success==true){
GroupCollection oGC=oMatch.Groups;
oStr+=oGC[0].Value+"\n";//整个匹配字符串
oStr+=oGC[1].Value+"\n";//第一个子匹配
MessageBox.Show(oStr);
}
re=new Regex(@"\:([^\:]+)");
oMatch=re.Match(str);
oStr="";
while(oMatch.Success==true)
{
GroupCollection oGC=oMatch.Groups;
//oStr+=oGC[0].Value+"\n";//整个匹配字符串
oStr+=oGC[1].Value+"\n";//第一个子匹配
oMatch=oMatch.NextMatch();
}
MessageBox.Show(oStr);
Regex re=new Regex(@"\?([^\?]+)\?\=");
Match oMatch=re.Match(str);
string oStr="";
if(oMatch.Success==true){
GroupCollection oGC=oMatch.Groups;
oStr+=oGC[0].Value+"\n";
oStr+=oGC[1].Value+"\n";
MessageBox.Show(oStr);
}