public static void main(String[] args) { String item = "CREATE TABLE \"cloud\".\"version\"\n" + "(\n" + " \"id\" BIGINT IDENTITY(43,1) NOT NULL,\n" + " \"version\" VARCHAR(50) NOT NULL,\n" + " \"updated\" TIMESTAMP(0) NOT NULL,\n" + " \"step\" CHAR(32) NOT NULL\n" + ");"; // 使用正则表达式匹配表名 Pattern tablePattern = Pattern.compile("\"\\w+\"\\.\"\\w+\""); Matcher tableMatcher = tablePattern.matcher(item); String tableName = ""; while (tableMatcher.find()) { tableName = tableMatcher.group(); } // 使用正则表达式匹配列名和长度 Pattern columnPattern = Pattern.compile("\"(\\w+)\" CHAR\\((\\d+)\\)"); Matcher tableColumnMatcher = columnPattern.matcher(item); while (tableColumnMatcher.find()) { String column = tableColumnMatcher.group(1); String charLength = tableColumnMatcher.group(2); System.out.println(tableName + " " + column + " " + charLength); } }
"cloud"."version" step 32