Q: Extract string from message using Dataweave I want to use Dataweave to pull out the text between the first : and first ( which in this case is "File incorrect" but in other cases it maybe different.
java.lang.Exception: File incorrect (javax.script.ScriptException). (org.mule.api.transformer.TransformerMessagingException).

I have looked at some of the string manipulation available and looks like you could only use it if you know the position of the text or the text you want to extract.
How can I do this?
Thanks

A: U can extract it using regex and match function in datatweave. Try the below Dwl
%dw 1.0

%var exceptionMsg = 'java.lang.Exception: File incorrect( javax.script.ScriptException). (org.mule.api.transformer.TransformerMessagingException).'
%output application/json
---
trim (exceptionMsg match /^(.*):([^(]*).*$/)[2]


A: You can make a call to groovy function from your Dateweave to extract the required string like bellow:
<configuration doc:name="Configuration">
<expression-language autoResolveVariables="false">
<global-functions>
def extractmsg(messageString) {
    int firstindex = messageString.indexOf(":");
    int endindex = messageString.indexOf("(");
    String msg = messageString.substring(firstindex+1, endindex).trim();
    return msg;
}
</global-functions>
</expression-language>
</configuration>

