54. Regex

Part 1

Part 2

In this tutorial, we go over how the Regex class (Regular Expression) works and how to create a Regex and find matches. Using Regex is a very easy way to parse strings and could save you a lot of time in the long run. This tutorial will cover the basics of finding Regex matches in a string, and you should be able to research yourself from there. Look up the Regex Syntax Reference Table for the characters that you can use in a Regex.

Code

Imports System.Text.RegularExpressions

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://services.runescape.com/m=itemdb_rs/frontpage.ws")
        Dim response As System.Net.HttpWebResponse = request.GetResponse

        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

        Dim rssourcecode As String = sr.ReadToEnd

        Dim r As New System.Text.RegularExpressions.Regex("")
        Dim matches As MatchCollection = r.Matches(rssourcecode)

        For Each itemcode As Match In matches

            ListBox1.Items.Add(itemcode.Value.Split("""").GetValue(5))

        Next

    End Sub

End Class