2012-10-05 10 views
0

나는 아래 SOQL 쿼리가 위해 :정규식 SOQL 쿼리 문자열은

SELECT Description,(Select Name,Id from Contacts) , Account.Name, (Select Id from Contacts) from Account

내가 다음 추출하는 자바에서 정규식을 적용 할 -

SELECT Description, Account.Name from Account

+2

잘 모르겠습니다. - SQL 쿼리 자체에서 상수 문자열을 추출 하시겠습니까? 아니면 여러 쿼리에 걸쳐 적용하고자하는 정규식의 예입니까? – DNA

답변

1

빠른 해결책은 커스텀에 맞게 조정을 주어진 표현 :

String query = "SELECT Description,(Select Name,Id from Contacts) , Account.Name, (Select Id from Contacts) from Account"; 

// Remove all subqueries (things in parenthesis) 
// Remove doubled commas (even with space in between) 
// Remove a comma before the from 
String answer = query 
    .replaceAll("\\(.*?\\)", "") 
    .replaceAll(",\\s*,", ",") 
    .replaceAll(",\\s*from", " from");