0

I have an expression Nvl(cost,Sum(cost1)) i need to remove string before paranthesis i.e NVl and Sum in this case

        String functions=externalFormat.replaceAll("\\([^\\(]*\\)", "");

Input Nvl(cost,Sum(Cost1) Output cost,cost1

1
  • Although not a neat way but you can use \w+\(|\) and replace with empty string. Commented May 16, 2019 at 11:55

2 Answers 2

1

If you can't use capture groups (ie, if you CAN use capture groups, (\w*?)\( will capture the text you need to replace in the first group)

You could use a positive look-ahead to only capture word characters (letter or number) that appear before an open bracket:

\w*(?=\()

You could even add optional white space characters in case of things like: Nvl1 (cost,Sum (cost1)) by including them before the look-ahead: -

\w*\s*(?=\()

Hope this helps solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

0

Check below code :

public static void main(String[] args) {
        String externalFormat="Nvl(cost,Sum(Cost1)";
        String functions=externalFormat.replaceAll("\\w+\\(|\\)", "");
        System.out.println(functions.toLowerCase());

    }

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.