Solved

Use Regular Expressions to Extract Data Fields in VB.NET

Posted on 2009-03-31
2
599 Views
Last Modified: 2013-11-07
Dear Experts,

I need to use regular expressions to extracted data fields in a string received from a device attached to a serial port. The strings look like the one below:

+IPR: (),(300,600,1200,2400,4800,9600,19200,38400,57600,115200,230400)

The data I want extracted is the one in braces. Using the sample string above, regex should extract the data as follows:

Field1= "" ' i.e. empty screen because there is no data in the first set of braces ()
Field2 = "300,600,1200,2400,4800,9600,19200,38400,57600,115200,230400" ' i.e. data in the second set of braces

There may be more braces with data in the received strings. The returned data can be in a single keyed list e.g.

DataFields(0)=""
DataFields(1)="300,600,1200,2400,4800,9600,19200,38400,57600,115200,230400"
DataFields(3)=...

Any idea how I can best implement this in VB.NET?
0
Comment
Question by:bmatumbura
2 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 24027741
Try this function, which returns a Generic list of type string.

Wayne
    Public Shared Function GetFields(ByVal fieldString As String) As List(Of String)
 

        Dim patt As String = "\((.*?)\)"

        Dim strList As New List(Of String)

        Dim mtchs As MatchCollection = Regex.Matches(fieldString, patt)

        For Each m As Match In mtchs

            strList.Add(m.Groups(1).Value)

        Next

        Return strList
 

    End Function

Open in new window

0
 
LVL 11

Author Closing Comment

by:bmatumbura
ID: 31564763
Thanks, works perfect!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now