import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(?<=^|;)\".*?\"(?=;|$)|(?<=^|;)[^;]*(?=;|$)";
final String string = "Name;inst_type;Position;Currency;cftype;amount;tenor;fwterm;compoundtype;resetterm;histrates;sdate;edate;fwdate;callput;capfloor;strike;vola;volavalue;ulspot;ulspotvalue;divcurve;cleanflag;fixrate;compfr;dayc;refindex;spread;floatfactor;paystart;payend;annuity;amortizingtype;cgm;resrate;nextrate;isprorated;rolldate;rollday;islongstub;isarrear;payrule;paydays;paycal;resrule;resdays;rescal;isfixcoupon;spreadcurve;cds_spread_value;recovrate;payoutrate;payrec;creditspread;disc;\"C\"\"F\"\n"
+ "Bond1;;1;EUR;2;100;6M;;;;;01.09.2007;01.09.2010;;;;;;;;;;;0,0625;1;1;;;;0;100;;;1;;;1;01.06.2008;;1;;;;;;;;;;;;;;;IR-EUR;\"2;01062008;100;0;0.0625;;01092007;01062008\";\"2;01122008;100;0;0.0625;;01062008;01122008\";\"2;01062009;100;0;0.0625;;01122008;01062009\";\"2;01122009;100;0;0.0625;;01062009;01122009\";\"2;01092010;100;0;0.0625;;01122009;01092010\";\"1;01092010;100\";\n"
+ "Bond2;;1;EUR;2;100;6M;;;;;01.09.2007;01.09.2010;;;;;;;;;;;0,0625;1;1;;;;0;100;;;-1;;;1;;;;;;;;;;;;;;;;;;IR-EUR;\"2;01092010;100;0;0.0625;;01032010;01092010\";\"2;01032010;100;0;0.0625;;01092009;01032010\";\"2;01092009;100;0;0.0625;;01032009;01092009\";\"2;01032009;100;0;0.0625;;01092008;01032009\";\"2;01092008;100;0;0.0625;;01032008;01092008\";\"2;01032008;100;0;0.0625;;01092007;01032008\";\"1;01092010;100\";";
final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
final Matcher matcher = pattern.matcher(string);
while (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html