Hello
I wonder if someone could help me figure out how to parse a string having the following format:
;field1-field2-fieldN;field1-field2-fieldN;
Each record is delimited by ';' and each field within a record is delimited by '-'. The complication is that the individual fields may contain escaped delimiter characters like so "\;" or "-". This causes my simple parsing code below to fail. So what I'm trying to do is come up with regex expressions that will match the delimiters but not match the escaped delimiters. My regex knowledge is not that great but I expected there must be a way of combining "([^\;])" and "([;])" to get what I require.
public static List<ParsedRecord> parse(String data) {
List<ParsedRecord> parsedRecords = new List<ParsedRecord>();
String[] records = data.split(";");
for (String record : records) {
String[] fields = data.split("-");
parsedRecords.add(new parsedRecord(fields));
}
return parsedRecords;
}
Thanks very much in advance.