import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "create table (\\w+)\\([\\s\\S]+?(?=\\)(?:\\n|$))";
final String string = "create table sous_branche(\n"
+ " id_sous_branche integer not null,\n"
+ " code_sous_branche character varying(20) not null,\n"
+ " libelle_sous_branche character varying(55) not null,\n"
+ " designation_sous_branche character varying(255) null,\n"
+ " taux_taxes float null,\n"
+ " date_creation timestamp without time zone null,\n"
+ " ref_importation integer null,\n"
+ " date_importation timestamp without time zone null\n"
+ ")\n"
+ "go\n"
+ "-- **** object: table caisse script date: 30/06/2015 16:53:15 ****\n"
+ "create table operation_caisse(\n"
+ " id_operation_caisse integer not null,\n"
+ " operation_id integer not null,\n"
+ " mode_paiement_id integer not null, --id_mode_paiement\n"
+ " libelle_paiement_caisse_id integer not null, --id_libelle_paiement\n"
+ " jour_imputation timestamp without time zone null,\n"
+ " date_paiement_caisse timestamp without time zone null,\n"
+ " numero_reglement integer null,\n"
+ " libelle_operation_caisse character varying(55) not null,\n"
+ " montant_operation_caisse double precision null,\n"
+ " payeur_effet_caisse_id integer not null, --id_payeur_effet\n"
+ " numero_effet_caisse character varying(30) null,\n"
+ " titulaire_compte_effet_caisse character varying(55) null,\n"
+ " date_encaissement_effet_caisse timestamp without time zone null,\n"
+ " autres_informations_caisse text null,\n"
+ " valider_commissionnement_caisse bit not null,\n"
+ " commissions_a_debiter_caisse real null,\n"
+ " numero_piece_caisse character varying(30) null,\n"
+ " piece_caisse_annulee bit not null,\n"
+ " date_annulation_piece_caisse timestamp without time zone null,\n"
+ " reference_annulation_piece_caisse character varying(55) null,\n"
+ " date_creation timestamp without time zone null,\n"
+ " ref_importation integer null,\n"
+ " date_importation timestamp without time zone null\n"
+ ")";
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