- Код: Выделить всё
<TD class="text"><B>###</B></TD>
<TD class=text>###</TD>
Заранее спасибо... =0
<TD class="text"><B>###</B></TD>
<TD class=text>###</TD>
Option Explicit
Public Function test(html)
Dim re As Object
Dim pos As Long
Set re = CreateObject("sgRegExp.RegExp")
re.Expression = "<TD class=text>([0-9]+)</TD>"
re.IgnoreCase = True
pos = 1
Do While (re.Match(html, pos))
Debug.Print re.Substrings(1)
With re.Substrings(0)
pos = pos + .Start + .Length - 1
End With
Loop
Set re = Nothing
End Function
Do While (re.Match(html, pos))
Debug.Print re.Substrings(1)
With re.Substrings(0)
pos = pos + .Start + .Length - 1
End With
Loop
<TR bgColor=#ffffff>
<TD class="headcell"><B>Система обратного осмоса А-445</B></TD>
<TD class=text>244</TD>
</TR>
<TR bgColor=#ffffff>
<TD class="headcell"><B>Система обратного осмоса А-560</B></TD>
<TD class=text>287</TD>
</TR>
re.Expression = "( +)<TD class=(.)headcell(.)><B>(.+)</B></TD>(\n +)<TD class=text>([0-9]+)</TD>"
f0rbeed писал(а):Вот у меня возник вопрос, что в этом куске твориться:
- Код: Выделить всё
Do While (re.Match(html, pos)) 'ищем подстроку по заданной маске с позиции pos
Debug.Print re.Substrings(1) 'чего-то делаем с найденным
With re.Substrings(0)
pos = pos + .Start + .Length - 1 'передвигаем позицию
End With
Loop
f0rbeed писал(а):И еще как потом эти числа поменять и записать?
Mid(html, pos + .Start - 1, .Length) = "666"
html = Left$(html, pos + .Start - 1) & "666" & Mid$(html, pos + .Start - 1 + .Length)
Option Explicit
Public Function test()
Dim iFF%, html$
iFF = FreeFile()
Open "c:\1\re.txt" For Input As #iFF
html = Input(LOF(iFF), iFF)
Close #iFF
html = search(html)
iFF = FreeFile()
Open "c:\1\re1.txt" For Output As #iFF
Print #iFF, html;
Close #iFF
End Function
Public Function search(html) As String
Dim re As sgRegExp.RegExp 'Object
Dim pos As Long
Set re = New sgRegExp.RegExp 'CreateObject("sgRegExp.RegExp")
re.Expression = "<TD class=text>([0-9]+)</TD>"
re.IgnoreCase = True
pos = 1
Do While (re.Match(html, pos))
With re.Substrings(1)
Debug.Print .Value
Mid(html, pos + .Start - 1, .Length) = "666"
End With
With re.Substrings(0)
pos = pos + .Start + .Length - 1
End With
Loop
Set re = Nothing
search = html
End Function
Сейчас этот форум просматривают: Majestic-12 [Bot], Yandex-бот и гости: 25