Reputation: 5440
I need to split a CSV file (which I read in as String) containing orders. Parsing rules of this CSV are not that complex:
Each order has several lines (no fix number)
Each order begins with one line (initiator):
111;222;dynamic content
Each order ends with two lines (terminator):
111;333;dynamic content
111;333;dynamic content
Initiator and terminator have to be included in the outcome of the split.
[EDIT] I do not need to use regexp. This was just my first idea. I could also use another solution, if it is easier. [/EDIT]
I have not much experience with regexp, so even getting started takes a long time :-( E.g., I tried the following:
String[] parts = body.split("111;333;.*111;333;");
Expected result: Splitter is 111;333; to 111;333; - remember, every order ends with two lines, both begin with 111;333; so, String[] should contain the correct number of orders IMO. However, there is only one String in the array which contains everything.
I played around with some other regexps, but I cannot get a good result. Can some one help me and tell me the regular expression for this split? Thanks...
Best regards, Kai
Upvotes: 2
Views: 294