Imports System
Imports System.Text.RegularExpressions
Public Class Test
Public Shared Sub Main()
Dim pattern As String = "^[ \t]* # beginning of line " & vbCrLf &
"[#]define[ \t]+ # PAWN #define " & vbCrLf &
"(?<name>[^\s\\;]+) # DEFINE_NAME " & vbCrLf &
"[ \t]*(?:\\\r?\n[ \t]*)? # spaces and optional \ " & vbCrLf &
"(?> # " & vbCrLf &
" (?<value>(?> # DEFINE_VALUE " & vbCrLf &
" [^\\\r\n;]+ | # Any char -except \ \n" & vbCrLf &
" \\[^\r\n][^\\\r\n;]* # \ within value " & vbCrLf &
" )+)? # (~unrolling the loop)" & vbCrLf &
" (?:\\\r?\n[ \t]*)? # \ for new line " & vbCrLf &
")* # repeated for each line"
Dim re As Regex = new Regex( pattern, RegexOptions.Multiline Or
RegexOptions.IgnorePatternWhitespace)
Dim text As String = "#define DEFINE_NAME \" & vbCrLf &
" DEFINE VALUE\" & vbCrLf &
" CONTINUE VALUE" & vbCrLf &
"#define TheName TheValue"
Dim mNum As Integer = 0
Dim matches As MatchCollection = re.Matches(text)
'Loop Matches
For Each match As Match In matches
'get name
Dim name As String = match.Groups("name").Value
Console.WriteLine("Match #{0} - Name: {1}", mNum, name)
'get values (in each capture)
Dim captureCtr As Integer = 0
For Each capture As Capture In match.Groups("value").Captures
'loop captures for the Group "value"
Console.WriteLine(vbTab & "Line #{0} - Value: {1}",
captureCtr, capture.Value)
captureCtr += 1
Next
mNum += 1
Next
End Sub
End Class