Java正規表現式でSQLコード、改行、余計スペースを除去

処理コード1:

public static void main(String[] args) { 
String sql = “SELECT * FROM \n" + 
" `testdb`.`foo` LIMIT 0, 100″; 
String s = “SELECT * FROM `testdb`.`foo` LIMIT 0, 100"; 
String sql2 = Pattern.compile(" {2,}").matcher(s).replaceAll(" “); 
String sql3 = s.replaceAll(" {2,}"," “); 
String sql4 = sql.replace('\r’, ' ').replace('\n’, ' ').replaceAll(" {2,}"," “);; 
String sql5 = sql.replace('\r’, ' ').replace('\n’, ' ').replaceAll(" {2,}?"," “);; 
String sql6 = sql.replace('\r’, ' ').replace('\n’, ' ').replaceAll(" {2,}+"," “);; 
System.out.println(sql2); 
System.out.println(sql3); 
System.out.println(sql4); 
System.out.println(sql5); 
System.out.println(sql6); 

処理コード2:

public boolean isAlreadySegmentSQL(String sql) { 
return sql.replace('\r’, ' ').replace('\n’, ' ').replaceAll(" {2,}", " “).matches(“(?i).+LIMIT [\\d+ *|\\d *, *\\d+].+"); 

 

処理コード3:

// regList.put(“(?i)bit\\([2-9]\\)\\z", “byte[]"); 
// regList.put(“(?i)bit\\(\\d{2,}\\)\\z", “byte[]"); 
regList.put(“(?i)bit\\((\\d{2,}|[2-9])\\)\\z", “byte[]"); 

 

 

Source

Posted by arkgame