0

我有以下 SOQL 查询:

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

我想在java中应用正则表达式来提取以下内容 -

SELECT Description, Account.Name from Account

4

1 回答 1

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");
于 2012-10-05T06:55:49.433 回答