I have rows of 8 numerical values in a text file that I have to parse. Each
value must occupy 10 spaces and can be either a decimal or an integer.
// these are valid - each fit in a 10 character block
123.8
123.8
1234.567
12345
12345
1234.567
// these are not valid
12 34.56 // whitespace in the middle of the value
1234 // occupies 11 spaces
// these are valid lines
// there is one value in each 10 character block
12345.678912345 .678912345.6789 12345.678912345 .678912345.6789 12345.678912345 .6789
345.6789 345.6789 45.6789 45.678912345.67 89 345.678912345.6 789
2345.6789
In reality the data can be in many different formats. (single values, rows
of 8 followed by an integer, rows of 10...) Currently I am parsing this with
code. For this example I read a line, break it up into an array of 8 values
of 10 characters each, and check to see if each one is numeric. If they are
all numeric, move on to the next line.
My biggest problem is how to deal with the whitespace. It can come before
the value, after the value, but not in the middle of the value. The value
can be of any length up to 10. It can be placed anywhere in the 10
character block and padded with whitespace. There are a lot of possible
variations. Also, I would like to generalize it to create the regular
expression on the fly for different formats.
Is there a way, using regular expressions, to specify a total width
including varing amounts of whitespace (depending on the size and position
of the value)?
Thanks for any help.
David