Im trying to parse a SQL table creation script in Java.
Ive currently got the following pattern:
Pattern p = Pattern.compile("(.+)([ ]+)(.+)([ ]+)(.+)");
i.e a group of any chars (column name), followed by one or more spaces, followed by another group of chars (column type), followed by one or more spaces, followed by any number of chars (i.,e not null etc).
And this is used by the following code:
Matcher m = p.matcher(field);
if(m.find()){
String column = m.group(1).trim();
String type = m.group(3).trim();
String clauses = m.group(5).trim();
}
And yet when I run this on:
firstColumn varchar(4) not null,
The first group is:
firstColumn varchar(4)
I would expect the three extracted fields to be firstColumn, varchar(4) and not null respectively.
Any ideas?