<td nowrap class="content_padding" valign="top">1</td>
<td nowrap class="content_padding" valign="top">1/141887</td>
<td nowrap class="content_padding" valign="top">
2011-6-17<br>10:44:46 PM<br>(星期五) </td>
<td nowrap class="content_padding" valign="top">
<div style="float:left">
<img src='../images/cards/H10.gif'> <img src='../images/cards/D8.gif'> </div> <td nowrap class="content_padding" valign="top">2</td>
<td nowrap class="content_padding" valign="top">3/144519</td>
<td nowrap class="content_padding" valign="top">
2011-6-17<br>10:44:34 PM<br>(星期五) </td>
<td nowrap class="content_padding" valign="top">
<div style="float:left">
<img src='../images/cards/DJ.gif'> <img src='../images/cards/S7.gif'> 想要的截取结果是:
text1(0)=1 text1(1)=1/141887 text1(2)=H10.gif text1(3)=D8.gif
text2(0)=2 text1(2)=1/144519 text1(2)=DJ.gif text1(3)=S7.gif高分求救,谢谢。
<td nowrap class="content_padding" valign="top">1/141887</td>
<td nowrap class="content_padding" valign="top">
2011-6-17<br>10:44:46 PM<br>(星期五) </td>
<td nowrap class="content_padding" valign="top">
<div style="float:left">
<img src='../images/cards/H10.gif'> <img src='../images/cards/D8.gif'> </div> <td nowrap class="content_padding" valign="top">2</td>
<td nowrap class="content_padding" valign="top">3/144519</td>
<td nowrap class="content_padding" valign="top">
2011-6-17<br>10:44:34 PM<br>(星期五) </td>
<td nowrap class="content_padding" valign="top">
<div style="float:left">
<img src='../images/cards/DJ.gif'> <img src='../images/cards/S7.gif'> 想要的截取结果是:
text1(0)=1 text1(1)=1/141887 text1(2)=H10.gif text1(3)=D8.gif
text2(0)=2 text1(2)=1/144519 text1(2)=DJ.gif text1(3)=S7.gif高分求救,谢谢。
perl脚本:csdn.pl 1 #!/usr/bin/perl
2
3 my ($i, $c);
4 open IN,$ARGV[0];
5 while(<IN>) {
6 if(/valign="top">(\d+)<\/td>/){
7 $c = 0;
8 $i = $1;
9 print "text$i($c)=$1 "; $c++;
10 }
11 if(/valign="top">(\d+\/\d+)<\/td>/){
12 print "text$i($c)=$1 "; $c++;
13 }
14 if(/images\/cards\/(.*gif)'>.*?\/images\/cards\/(.*?gif)'>/){
15 print "text$i($c)=$1 "; $c++;
16 print "text$i($c)=$2\n";
17 }
18 }
19 close IN;命令行:perl csdn.pl csdn.txt
结果:text1(0)=1 text1(1)=1/141887 text1(2)=H10.gif text1(3)=D8.gif
text2(0)=2 text2(1)=3/144519 text2(2)=DJ.gif text2(3)=S7.gif
'此代码由“正则测试工具 v1.1.34”自动生成,请直接调用TestReg过程
Private Sub TestReg()
Dim strData As String
Dim reg As Object
Dim matchs As Object, match As Object strData = "<td nowrap class=""content_padding"" valign=""top"">1</td>" & vbCrLf & _
"<td nowrap class=""content_padding"" valign=""top"">1/141887</td>" & vbCrLf & _
"<td nowrap class=""content_padding"" valign=""top"">" & vbCrLf & _
"2011-6-17<br>10:44:46 PM<br>(星期五) </td>" & vbCrLf & _
"<td nowrap class=""content_padding"" valign=""top"">" & vbCrLf & _
"<div style=""float:left"">" & vbCrLf & _
"<img src='../images/cards/H10.gif'> <img src='../images/cards/D8.gif'> </div>" & vbCrLf & _
" <td nowrap class=""content_padding"" valign=""top"">2</td>" & vbCrLf & _
" <td nowrap class=""content_padding"" valign=""top"">3/144519</td>" & vbCrLf & _
" <td nowrap class=""content_padding"" valign=""top"">" & vbCrLf & _
" 2011-6-17<br>10:44:34 PM<br>(星期五) </td>" & vbCrLf & _
" <td nowrap class=""content_padding"" valign=""top"">" & vbCrLf & _
" <div style=""float:left"">" & vbCrLf & _
"<img src='../images/cards/DJ.gif'> <img src='../images/cards/S7.gif'> " Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.IgnoreCase = True
reg.MultiLine = True
reg.Pattern = "top"">(\d+)</td>[\s\S]+?top"">(\d+/\d+)</td>[\s\S]+?<img src='../images/cards/(.+?\.gif)'> <img src='../images/cards/(.+?\.gif)'>"
Set matchs = reg.Execute(strData)
For Each match In matchs
'Debug.Print match.Value
Debug.Print match.SubMatches(0) & VBTAB & match.SubMatches(1) & VBTAB & match.SubMatches(2)
Next
Debug.Print
End Sub
Dim reg As Object
Dim matchs As Object, match As Object
strData = Text10.Text
Set reg = CreateObject("vbscript.regExp")
reg.Global = True
reg.IgnoreCase = True
reg.MultiLine = True
reg.Pattern = "top"">(\d+)</td>[\s\S]+?top"">(\d+/\d+)</td>[\s\S]+?<img src='../images/cards/(.+?\.gif)'> <img src='../images/cards/(.+?\.gif)'>"
Set matchs = reg.Execute(strData)
For Each match In matchs
'Debug.Print match.Value
Debug.Print match.SubMatches(0) & vbTab & match.SubMatches(1) & vbTab & match.SubMatches(2)
Next
Debug.Print请问这样赋值过后为什么就找不出来了呢?