I have the below SOQL query:
SELECT Description,(Select Name,Id from Contacts) , Account.Name, (Select Id from Contacts) from Account
I want to apply regex in java to extract following -
SELECT Description, Account.Name from Account
I have the below SOQL query:
SELECT Description,(Select Name,Id from Contacts) , Account.Name, (Select Id from Contacts) from Account
I want to apply regex in java to extract following -
SELECT Description, Account.Name from Account
Quick solution custom tailored to the expression given:
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");