I have an expression Nvl(cost,Sum(cost1)) i need to remove string before paranthesis ie NVl and Sum in this case
String functions=externalFormat.replaceAll("\\([^\\(]*\\)", "");
Input Nvl(cost,Sum(Cost1) Output cost,cost1
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.
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());
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.