Regular Expression Help Needed!  
Author Message

PostPosted: Regular Expressions, Regular Expression Help Needed! Top

I have lines of text I am reading in and am trying to match the line with regex but I dont know if my pattern is correct.

The line looks like this, but multi cols, tab delimited.
0    38.159481
0.01    38.159481
0.02    38.312172
0.03    38.159481
0.04    38.159481
0.05    38.312172
0.06    38.312172
0.07    38.159481
0.08    38.464859
0.09    38.159481
0.1    38.159481

I just want the 0 and 0.1 and so forth on down.

This is my pattern Im using:

[code language="vb"]Dim mystreamreader As StreamReader
Dim myStreamWriter As StreamWriter
Dim fi As New FileInfo(myoldfile)
Dim pattern As String = "^\d*(.[1-9]) |\.[1-9]\t.+"
myStreamWriter = File.CreateText(myfile)
mystreamreader = File.OpenText(myoldfile)
Dim myRegEx As New System.Text.RegularExpressions.Regex(pattern)

Dim myInputString As String = mystreamreader.ReadLine

Do Until mystreamreader Is Nothing
    myInputString = mystreamreader.ReadLine()

    If myRegEx.IsMatch(myInputString) Then
    End If

I am reading the lines ok, but its not matching what I want.

Any clues

(Moderator: Thread moved to this forum for better responses)

.NET Development24  

PostPosted: Regular Expressions, Regular Expression Help Needed! Top

I came across your post and just know you have been waiting for all this time for an answer. <g>

The code example suggests that all lines that match will be outputed...yet you mentioned you only want one column...

The below regex will look for two columns and place them into named groups if such functionality is needed. Get group 0 or referenced by "Col1" for the data. I like the groups because it makes the regex easier to understand by sight. I had the whitespace placed into a non capture group, which helps with anchoring but does not cloud final data output.