I'm working with VB.NET and I'm working with a RESTful API... They have a construction for selecting resources (Includes) and fields. I've written a wrapper and want to add syntax checking before making any calls. I'm wanting to use RegEX but am struggling to understand and need help.
The calling syntax structure is nested up to 3 levels with field selection for each nested association (Include) as follows:
Include,Include/Subinclude,Include/Subinclude/Subinclude,Include/Subinclude(field)/Subinclude,Include(field,field,...,field)/Subinclude(field,field,...,field),...,Include(field,field,...,field)/Subinclude(field,field,...,field)/Subinclude(field,field,...,field)
Fields must be associated with Includes seperated by commas and are only lowercase letters, numbers & the '_' underscore character
Includes are seperated by commas and are title case letters & numbers
Includes can optionally specify one or more fields wrapped in braces. eg. Include(field,field,...,field)
Includes can be nested with two-sub levels. Subincludes are nested using '/' and are title case letters & numbers. eg. Include/Subinclude/Subinclude
Every sub-include can have fields like Includes.
There can be any number of each type of element, usage is variable, and Includes can only be nested to 3 levels (Include/Subinclude/Subinclude).
Here's a example:
Listing(listing_id,user_id,title,materials,tags,url)/Images(listing_image_id,url_75x75),Listing(listing_id)/User(user_id,login_name),Buyer(user_id,login_name),Author(user_id,login_name,feedback_info)/Profile,Subject(user_id,login_name)/User(user_id)/Profile(user_profile_id,login_name),Listing/User/Shops,Listing/User(user_id,login_name)/Shops,Listings/Images,Subject/User/Profile(user_profile_id,login_name)
And here's the RegEx code that I've created so far:
[0-9a-fA-F]*((.|\n)*?)(\(|\)|,|\\)
I can code this in VB.NET but am wanting to use RegEx for its speed benefits. I'm trying to stripe out all text and build a nested representation. It would look something like:
Listing(listing_id,user_id,title,materials,tags,url)/Images(listing_image_id,url_75x75),
Listing(listing_id)/User(user_id,login_name),
Buyer(user_id,login_name),
Seller(user_id,login_name),
Author(user_id,login_name,feedback_info)/Profile,
Subject(user_id, login_name)
Then further down into sub sections, and so on with group names. Being able to identify level/type groups would be a bonus...
I'm sure this is dead easy but am not sure how to work with nested multi-level optional elements in RegEx and would really appriciate some help from the gurus...
Here's the storage class definition where the results will be kept:
Public Class Include
Public fields As List(Of String)
Public Includes As Includes(Of Include)
Sub New()
Includes = New Includes(Of Include)
End Sub
End Class
And the collection class definition:
Public Class Includes(Of Include) : Implements IEnumerable(Of include)
#Region "Constructor"
Public Sub New()
End Sub
#End Region
#Region "Public Properties"
Private _Includes As New List(Of include)
Default Public Property Item(ByVal index As Integer) As include
Get
Return _Includes(index)
End Get
Set(ByVal value As include)
Try
_Includes.Remove(value)
Catch ex As Exception
End Try
_Includes.Add(value)
End Set
End Property
#End Region
#Region "Pulic Methods & Functions"
Public Sub Clear()
_Includes.Clear()
End Sub
Public Sub Add(ByVal item As include)
_Includes.Add(item)
End Sub
Public Function Count() As Integer
Return _Includes.Count
End Function
Public Function GetEnumerator() As System.Collections.Generic.IEnumerator(Of include) _
Implements IEnumerable(Of include).GetEnumerator
Return _Includes.GetEnumerator
End Function
Public Function GetEnumerator1() As System.Collections.IEnumerator _
Implements IEnumerable.GetEnumerator
Return _Includes.GetEnumerator
End Function
#End Region
#Region "Boxing"
Public Shared Narrowing Operator CType(ByVal src As includes(Of include)) As include()
Dim dest(src.Count) As include
For i As Integer = 0 To src.Count - 1
dest(i) = src(i)
Next
Return dest
End Operator
Public Shared Widening Operator CType(ByVal src As include()) As includes(Of include)
Dim dest = New includes(Of include)
For i As Integer = 0 To src.Count - 1
dest.Add(src(i))
Next
Return dest
End Operator
#End Region
End Class
Thanks...