public static String[] parserValues(String values) { String patternStr = "([^\\,]*)[\\,]?"; // 解析字段值 String patternStr1 = "('?[^\\,]*'?)[\\,]?"; // 解析字段值 /** * 编译正则表达式patternStr,并用该表达式与传入的sql语句进行模式匹配, * 如果匹配正确,则从匹配对象中提取出以上定义好的6部分,存放到数组中并返回 该数组 */ String[] ret = RegexUtil.containWithPatternMatcherInput(values,patternStr1); PatternCompiler compiler = new Perl5Compiler(); Pattern pattern = null; try { pattern = compiler.compile(patternStr, Perl5Compiler.CASE_INSENSITIVE_MASK); } catch (MalformedPatternException e) { e.printStackTrace(); return null; } PatternMatcher matcher = new Perl5Matcher(); MatchResult result = null; String[] tokens = null; boolean match = matcher.matches(values.trim(), pattern); System.out.println(match); if (match) { result = matcher.getMatch(); tokens = new String[6]; for (int i = 0; i < 6; i++) { tokens[i] = result.group(i + 1).trim(); System.out.println(tokens[i]); } } return tokens; }
public static String[] parseField(String fieldStr) { // ( soundCode , soundName , soundFileName ) //fieldStr = fieldStr.trim(); // String regx = "\\([\\s*([^\\,]+)\\,?]+\\)"; String regx = "([^\\,^\\(^\\)]+)\\s*\\,?\\s*"; return RegexUtil.containWithPatternMatcherInput(fieldStr,regx); // PatternCompiler compiler = new Perl5Compiler(); // Pattern pattern = null; // try // { // pattern = compiler.compile(regx, // Perl5Compiler.CASE_INSENSITIVE_MASK); // } // catch (MalformedPatternException e) // { // e.printStackTrace(); // return null; // } // PatternMatcher matcher = new Perl5Matcher(); // MatchResult result = null; // String[] tokens = null; // if (matcher.matches(fieldStr, pattern)) // { // result = matcher.getMatch(); // // tokens = new String[result.groups()]; // for (int i = 0; i < result.groups(); i++) // { // tokens[i] = result.group(i + 1).trim(); // } // } // return tokens; }