user38349
user38349

Reputation: 3025

Why is Regex VB.Net Dropping "-" When Getting Matches?

Trying to parse this and return the following 3 items:

  1. -30.25 31.46 -27.46 31.74
  2. -24.57 32.03 -16.86 32.88
  3. -13.82 33.19 -9.69 33.62

Using this regex expression below I get the matches, but drop the leading "-" at the front of each grouping. I get the "-" in the middle of the group though. Here is the expression I currently use.

Dim regex As New System.Text.RegularExpressions.Regex("\b\-{0,1}\d{1,2}\.{0,1}\d{0,2}\s{1}\-{0,1}\d{1,2}\.{0,1}\d{0,2}\s{1}\-{0,1}\d{1,2}\.{0,1}\d{0,2}\s{1}\-{0,1}\d{1,2}\.{0,1}\d{0,2}\b", RegexOptions.Singleline)

Thanks!

Here is the source text: [Airports]

[Airways]

-30.25 31.46 -27.46 31.74

-24.57 32.03 -16.86 32.88

-13.82 33.19 -9.69 33.62

[Arcs]

Upvotes: 0

Views: 85

Answers (2)

Rubens Farias
Rubens Farias

Reputation: 57956

If I correctly understood your sample, try to use this: (-?\d+\.\d+ ?){4}

Upvotes: 0

JoelFan
JoelFan

Reputation: 38714

\b will not match at the beginning of your input if the first character is a dash (-)

Upvotes: 2

Related Questions