I am parsing the following table of AWS instances:
m1.small 1 1 1.7 1 x 160 $0.044 per Hour m1.medium 1 2 3.75 1 x 410 $0.087 per Hour m1.large 2 4 7.5 2 x 420 $0.175 per Hour m1.xlarge 4 8 15 4 x 420 $0.35 per Hour
There is a file with such costs:
input = new Scanner(file); String[] values; while (input.hasNextLine()) { String line = input.nextLine(); values = line.split("\\s+"); // <-- not what I want... for (String v : values) System.out.println(v); }
However, this gives me:
m1.small 1 1 1.7 1 x 160 $0.044 per Hour
which is not what I want ... The corrected parsing of the values (with the correct regular expression) will look like this:
['m1.small', '1', '1', '1.7', '1 x 160', '$0.044', 'per Hour']
What will regex be to get the right result? It can be assumed that the table will always have the same template.
java string regex parsing
cybertextron
source share