0

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

1
  • 3
    Not sure I understand - you want to extract a constant string from the SQL query itself? Or is this just an example of a regex you want to apply across many queries? Commented Oct 5, 2012 at 6:48

1 Answer 1

1

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.