[Help]Regex[Solved]

Posts 1–6 of 6 · Page 1 of 1
Quick question first , do you realize you have a extra space, which effects it

just checking "'post entry-content '>" extra space ofter the t
Umm...Simple soultion to a simple problem

And yes, I think there is not an extra space after 't' as you pasted... but no worries

The following code gets everything between "<div class='post entry-content '>' and '</div>'.

Personal Suggestion: Don't dive into regex expressions when u can do it with simple string formatting techniques. I know regexes are the most efficient but just avoid them if not having firm understanding....

[php]
Sub ReadTag()
Dim file As String = "D:\ppl2pass.txt"
Dim filereader As New IO.StreamReader(file)

Dim extraction As String = ""
Dim flag As Boolean = False

While Not filereader.EndOfStream

Dim CurrentLine As String = filereader.ReadLine()

'No issue if there's a space or not

If CurrentLine.StartsWith("<div class='post entry-content") Then
flag = True
Continue While
End If
If CurrentLine.StartsWith("</div>") Then
flag = False
End If

If flag Then
extraction += CurrentLine & vbCrLf
End If
End While
extraction = extraction.Trim
MsgBox(extraction)
End Sub
[/php]

Now just call this subprocedure from where-ever you want !!

Have Fun
yah you need a space there.
thanks does the code extract each string?

also what if this is the reader.

Code:
  Dim Request As HttpWebRequest = HttpWebRequest.Create("http://peterpanh4x.nintendolegends.com/forums/index.php?/topic" & Topic4Site)
        Dim Response As HttpWebResponse = Request.GetResponse()
        Dim reader As StreamReader = New StreamReader(Response.GetResponseStream)
        Dim httpContent As String
        httpContent = reader.ReadToEnd
---

edit
used your code. didnt work.
Quote Originally Posted by ppl2pass View Post
thanks does the code extract each string?

also what if this is the reader.

Code:
  Dim Request As HttpWebRequest = HttpWebRequest.Create("http://peterpanh4x.nintendolegends.com/forums/index.php?/topic" & Topic4Site)
        Dim Response As HttpWebResponse = Request.GetResponse()
        Dim reader As StreamReader = New StreamReader(Response.GetResponseStream)
        Dim httpContent As String
        httpContent = reader.ReadToEnd
---

edit
used your code. didnt work.

Working for me...I think you are doing something wrong...

And there are more than 1 lines of '<div class='post entry-content', so it will catch all. you then need to determine which one should remain on the final string.

Well here's the final code [Tested and working perfectly fine]:

[php]
Sub ReadTag()
Dim Request As HttpWebRequest = HttpWebRequest.Create("http://peterpanh4x.nintendolegends.com/forums/index.php?/topic" & Topic4Site)
Dim Response As HttpWebResponse = Request.GetResponse()
Dim reader As StreamReader = New StreamReader(Response.GetResponseStream)
Dim httpContent As String
httpContent = reader.ReadToEnd

Dim File As String = My.Computer.FileSystem.GetTempFileName() & Rnd() * 777
My.Computer.FileSystem.WriteAllText(File, httpContent, False)

Dim filereader As New IO.StreamReader(File)
Dim extraction As String = ""
Dim flag As Boolean = False
While Not filereader.EndOfStream
Dim CurrentLine As String = filereader.ReadLine()

'No issue if there's a space or not

If CurrentLine.Trim.Contains("<div class='post entry-content") Then
flag = True
Continue While
End If
If CurrentLine.Trim.Contains("</div>") Then
If flag Then

'This will seperate the other tags...so you can recognize them !
extraction += "***************************************" & vbCrLf

End If
flag = False

End If

If flag Then
extraction += CurrentLine & vbCrLf
End If
End While
My.Computer.FileSystem.DeleteFile(File, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently, FileIO.UICancelOption.DoNothing)
extraction = extraction.Trim
MsgBox(extraction)

End Sub


[/php]

I hope this code will work fine on your side too, If not then feel free to ask !!
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us