I’m trying to figure out a way to parse strings that contain about 3-4 columns of data with variable whitespace between each element. I’d like to split each line into its respective components. Examples are below:
WHITE BLOOD CELL COUNT 10.2 4.0-10.8
HEMOGLOBIN 8.9 ABNORMAL LOW 12-16
PLATELET COUNT 250 160-400
So in the above examples, two lines have three elements, one line has four elements. I want to find a way separate it. If the first element were one word it would be easy, but I don’t see a simple way to do this other than going through each character and matching for either letter or number/period/dash and doing it that way.
Your data can be separated into rows using:
Then, for each row, you can split the data by columns using:
Here is a demonstration: http://codepad.org/BdCHu8PO