I have a string like:
17:27 - 13:10(+1 day) Trip duration 13h43 New York (JFK) 1 x transfer Includes travel by bus Maastricht (ZYT) Lowest fare USD 862 View flight details
I want to get certain texts from the string like departing time or price. But the strings can be of different lengths and texts so I need rules to be able to get the sub-strings I need.
What I know: Times are formatted like 17:27 - 13:10 with depart time on left and arrival time on the right of -, locations as New York (JFK) where the first is depart location and the second is arrival location, transfers are a number followed by an x like 1 x, and a price is a number that comes after USD text like USD 862
So in the above example text, the data I want to extract from the string is: 17:27, 13:10, New York (JFK), 1, Maastricht (ZYT), and 862
To explain it better, say I know a specific string like the one I gave above, I would like to extract it like this:
String text = "17:27 - 13:10(+1 day) Trip duration 13h43 New York (JFK) 1 x transfer Includes travel by bus Maastricht (ZYT) Lowest fare USD 862 View flight details";
String departTime = text.substring(0, 5);
String arrivalTime = text.substring(8, 13);
String depart = text.substring(42, 56);
String arrive = text.substring(93, 109);
String transfers = text.substring(57, 58);
String price = text.substring(126, 129);
System.out.println(" departTime: "+departTime+"\n arrivalTime: "+arrivalTime+"\n depart: "+depart+"\n arrive: "+arrive+"\n transfers: "+transfers+"\n price: "+price);
But this won't work as the cases are different. Below are more text examples:
18:50 - 13:10(+1 day) Trip duration 12h20 New York (JFK) 1 x transfer Includes travel by bus Maastricht (ZYT) KL0646 Inflight services: Lowest fare USD 862 View flight details
12:00 - 13:10(+1 day) Trip duration 19h10 New York (JFK) 2 x transfer Includes travel by bus Maastricht (ZYT) Inflight services: FromUSD 864 View flight details
12:00 - 13:10(+1 day) Trip duration 19h10 New York (JFK) 2 x transfer Includes travel by bus Maastricht (ZYT) FromUSD 864 View flight details 3 seats left at this fare
07:45 - 13:10(+1 day) Trip duration 23h25 New York (JFK) 2 x transfer Includes travel by bus Maastricht (ZYT) FromUSD 864 View flight details 1 seat left at this fare