Solved

Use Regular Expressions to Extract Data Fields in VB.NET

Posted on 2009-03-31
2
602 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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Vb. Net application freezes 9 47
Show/Hide ASP.NET controls with JQuery best practices 3 50
VB.NET (2008) - Refactoring Question 2 21
Error handling in asp.net site 5 28
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
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…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

803 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