tags:

views:

51

answers:

2

Alright so I want to grab the information on a website thats between

[usernames] and [/usernames]

I know how to get the string but how would I use regex to only have the information in the middle.

Remember I am going to be having more then one thing on the page.

+1  A: 

You are better off parsing the document for every instance.

regex to match one instance would be

/<usernames>([^<]+?)<\/usernames>/
Mimisbrunnr
+2  A: 
    'Sample input
    Dim html = "<html><head><title>Test</title></head>" & vbNewLine & "<body><p>[usernames]Your Name Here[/usernames]</p>[usernames]Another Name Here[/usernames]</body></html>"
    'Named pattern
    Dim p = "\[usernames\](?<UserNames>.*?)\[/usernames\]"
    'Grab all of the matches
    Dim Matches = Regex.Matches(html, p, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
    'Make sure we found something
    If Matches IsNot Nothing AndAlso Matches.Count > 0 Then
        'Loop through all of the matches
        For Each Match As Match In Matches
            'Make sure our sub-group was a success
            If Match.Groups("UserNames").Success Then
                Trace.WriteLine(Match.Groups("UserNames").Value)
            End If
        Next
    End If
Chris Haas