Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Use Regular Expressions to Extract Data Fields in VB.NET

Posted on 2009-03-31
2
Medium Priority
?
611 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 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

877 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