<td width="201">001:Aman'Thul DE A</td>
<td width="201">002:Dalvengyr DE H</td>
<td width="201">003:Der Mithrilorden DE H</td>
<td width="201">004:Die Arguswacht DE A</td>
<td width="201">008:Kult der Verdammten DE A</td>请问怎样提取Aman'Thul ,Dalvengyr,Der Mithrilorden,Kult der Verdammten 到<area> 提取 H,A到<type>中..我现在的表达式:
[^:]*?:(?<area>[\S\s]+)\s+?(?<type>[HA])
不能满足..
<td width="201">002:Dalvengyr DE H</td>
<td width="201">003:Der Mithrilorden DE H</td>
<td width="201">004:Die Arguswacht DE A</td>
<td width="201">008:Kult der Verdammten DE A</td>请问怎样提取Aman'Thul ,Dalvengyr,Der Mithrilorden,Kult der Verdammten 到<area> 提取 H,A到<type>中..我现在的表达式:
[^:]*?:(?<area>[\S\s]+)\s+?(?<type>[HA])
不能满足..
Groups[1]=类似于“<td width="201">”这一段
Groups[2]=就是你要的字符串
(<td[^>]+>\d{3}:)([^<]+)</td>
这个可以得到你想要的结果。
正确
单独的Aman'Thul A
然后 Dalvengyr H
再
Der Mithrilorden H...........
呵呵,有正则问题直接PM我就行了,也不用浪费这些分了
将匹配得到的string1分成两段就是你要的。
type=string1.Lastindexof(0);
area=string1.Replace(type,"");
每事反正有分的嘛...
===============
因为Hakkar 这里可能包含H或A,所以不能用[^HA],如果area里可能有回车,那就那.换成[\s\S],因为后面的H或A肯定存在,所以[HA]这样写就可以,但要判断一下两侧的条件,嗯,前面的\s*?还是用你的\s+好一点:\s*?(?<area>[\s\S]*?)\s+?(?<type>[HA])(?=\s|$)
============================================
才看到上面的回复,那这样:\s*?(?<area>[\s\S]*?)\s+?(?<type>[HA])(?=<|\s|$)是几个单词无所谓,因为前面的“:”和后面的“[HA]”,已经把范围限定死了,只要把“[HA]”两侧的条件限定一下就行了
============================================
或者这样写,就不用考虑“[HA]”后面的具体情况了:\s*?(?<area>[\s\S]*?)\s+?(?<type>\b[HA]\b)
===============================================这些就是你的回复啊..前面才翻出来看了的...===========
对DE是固定的..
:\s*?(?<area>[\s\S]*?)\s+?(?<type>\b[HA]\b)
在这也是可以用的,只不过是多了 DE ,需要再分离一下就可以了,用我上面给的那个吧<td[^>]*?>[^:]*?:(?<area>[\s\S]*?)\s*?DE\s*?(?<type>\b[HA]\b)</td>
<td width="11" height="22"> </td>
<td width="201">002:Dalvengyr DE H</td>
<td width="82">0.14元/金币</td>
<td width="70" align="center">200</td>
<td width="70" align="center">1000</td>
<td width="42" align="center"> 正常 </td> <table width="518" border="0" align="center" cellpadding="0" cellspacing="0" class=text>
<tr>
<td width="11" height="22"> </td>
<td width="201">017:Agamaggan UK A</td>
<td width="82">0.10元/金币</td>
<td width="70" align="center">200</td>
<td width="70" align="center">0</td>
<td width="42" align="center"> <font color="8D3917">满仓</font> </td>
<td width="42" align="center">
<font color="8D3917">满仓</font>
</font></td>
</tr>
</table>式子:
<tr>\s+<td[^>]*?>\s+</td>\s+<td[^>]*?>[^:]*?:(?<area>[\S\s]*?)\s+(?<type>[AH])</td>\s+<td[^>]*?>(?<price>0\.\d{1,2})[^<]*?</td>\s+<td[^>]*?>[^<]*?</td>\s+<td[^>]*?>(?<num>[^<]*?)</td>\s+<td[^>]*?>(<font[^>]*?>)?(?<state>)[^<]*?(</font>\s+)?</td>不能匹配,,
都写累了.眼花
<td width="42" align="center">
<font color="8D3917">满仓</font>
</font></td>匹配上面的用这个吧<tr>\s+<td[^>]*?>[^<]*?</td>\s+<td[^>]*?>[^:]*?:(?<area>[\S\s]*?)\s+(?<type>[AH])</td>\s+<td[^>]*?>(?<price>0\.\d{1,2})[^<]*?</td>\s+<td[^>]*?>[^<]*?</td>\s+<td[^>]*?>(?<num>[^<]*?)</td>\s+<td[^>]*?>(<font[^>]*?>)?(?<state>)[^<]*?(</font>\s+)?</td>前面那个空格不知是全角还是什么的,\s+匹配起来有问题,还是改成[^<]*?吧
http://www.pvp-wow.com/pvp/youxi.asp?catid=27
我的:282944601明天没解决再Q你,哈
<tr>\s+<td[^>]*?>[^<]*?</td>\s+<td[^>]*?>[^:]*?:(?<area>[\s\S]*?)\s*?(\S+)\s*?(?<type>\b[HA]\b)</td>\s+<td[^>]*?>(?<price>0\.\d{1,2})[^<]*?</td>\s+<td[^>]*?>[^<]*?</td>\s+<td[^>]*?>(?<num>[^<]*?)</td>\s+<td[^>]*?>\s*(<font[^>]*?>)?(?<state>[^<]*?)(</font>)?\s*</td>
我的测试代码
string yourStr = richTextBox1.Text;
MatchCollection mc = Regex.Matches(yourStr, @"<tr>\s+<td[^>]*?>[^<]*?</td>\s+<td[^>]*?>[^:]*?:(?<area>[\s\S]*?)\s*?(\S+)\s*?(?<type>\b[HA]\b)</td>\s+<td[^>]*?>(?<price>0\.\d{1,2})[^<]*?</td>\s+<td[^>]*?>[^<]*?</td>\s+<td[^>]*?>(?<num>[^<]*?)</td>\s+<td[^>]*?>\s*(<font[^>]*?>)?(?<state>[^<]*?)(</font>)?\s*</td>", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["area"].Value + "\n";
richTextBox2.Text += m.Groups["type"].Value + "\n";
richTextBox2.Text += m.Groups["price"].Value + "\n";
richTextBox2.Text += m.Groups["num"].Value + "\n";
richTextBox2.Text += m.Groups["state"].Value + "\n\n";
}不过我看DE、UK等等代表的是国家,那个不取到area里吗,这里没有取到里面