import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "^[\\s]*@wb_export[\\s]+def ([\\w]+)\\(jsonstr\\):[\\s\\S]*?\"\"\"(\\{\"in\":.*)\"\"\"([\\s\\S]*?)((@|$)[\\s\\S]*)$";
final String string = "@wb_export\n"
+ "def SimpleFunction(jsonstr):\n"
+ " #global fd\n"
+ " #os.write(fd, \"wb_pre\\n\")\n"
+ " \n"
+ " # Definition of Input and Output Parameters (name and type)\n"
+ " \"\"\"{\"in\": {\"param\":\"string\"}, \"out\": {\"return\":\"string\"}}\"\"\"\n"
+ " # /!\\ Do not edit here !\n"
+ " # Edit function SimpleFunctionImpl() in \"common\" part\n"
+ " \n"
+ " import json,os,sys,datetime\n"
+ " inputData = json.loads(jsonstr)\n"
+ " \n"
+ " try:\n"
+ " outputData = SimpleFunctionImpl(inputData[\"param\"])\n"
+ " fd = os.open(\"../log/custom_success.log\", os.O_APPEND|os.O_CREAT|os.O_RDWR)\n"
+ " os.write(fd, \"%s In : %s / Out : %s\\n\" % (datetime.datetime.now().strftime(\"[%Y-%m-%d %H:%M:%S.%f]\"), jsonstr, json.dumps(outputData)))\n"
+ " os.close(fd)\n"
+ " return json.dumps(outputData)\n"
+ " except Exception as e:\n"
+ " fd = os.open(\"../log/custom_error.log\", os.O_APPEND|os.O_CREAT|os.O_RDWR)\n"
+ " os.write(fd, \"%s INTERNAL ERROR: Custom code uncatched exception in VCO::SimpleFunction().\\n\\tIn : %s\\n\\tMessage: %s\\n\" % (datetime.datetime.now().strftime(\"[%Y-%m-%d %H:%M:%S.%f]\"), jsonstr, str(e)))\n"
+ " os.close(fd)\n"
+ " return json.dumps({\"error\":\"INTERNAL ERROR: Custom code uncatched exception in VCO::SimpleFunction.\\n\\tMessage: %s\" % str(e)})\n"
+ " except:\n"
+ " fd = os.open(\"../log/custom_error.log\", os.O_APPEND|os.O_CREAT|os.O_RDWR)\n"
+ " os.write(fd, \"%s INTERNAL ERROR: Custom code uncatched system exception in VCO::SimpleFunction().\\n\" % (datetime.datetime.now().strftime(\"[%Y-%m-%d %H:%M:%S.%f]\")))\n"
+ " os.close(fd)\n"
+ " return json.dumps({\"error\":\"INTERNAL ERROR: Custom code uncatched system exception in VCO::SimpleFunction().\"})\n"
+ " # End of SimpleFunction - VCO WB Custom Code Editor\n"
+ "@wb_export\n"
+ "def SimpleFunction2(jsonstr):\n"
+ " #global fd\n"
+ " #os.write(fd, \"wb_pre\\n\")\n"
+ " \n"
+ " # Definition of Input and Output Parameters (name and type)\n"
+ " \"\"\"{\"in\": {\"param\":\"string\"}, \"out\": {\"return\":\"string\"}}\"\"\"\n"
+ " # /!\\ Do not edit here !\n"
+ " # Edit function SimpleFunctionImpl() in \"common\" part\n"
+ " \n"
+ " return {\"return\": \"OK2\"}\n"
+ " \n"
+ " \n"
+ " \n"
+ " ";
final Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html