...
More information on the flags available to the regular expression engine here: https://docs.oracle.com/javase/tutorial/essential/regex/pattern.html.
Source code is here: https://developer.classpath.org/doc/java/util/regex/Pattern-source.html. If you need the Flag values.
Code Block | ||
---|---|---|
| ||
var modifiedBody = body; var bodyDelimiters = ["Your expression 1", "Your expression 2"]; //These correspond to the flags mentioned in https://docs.oracle.com/javase/tutorial/essential/regex/pattern.html var dotAllFlag = 0x20; var multilineFlag = 0x08; var unicodeCaseFlag= 0x40; //Add the desired flags here var regexpFlags = dotAllFlag | multilineFlag | unicodeCaseFlag print('Number of body delimiters [' + bodyDelimiters.length + '].'); //Each delimeter is processed in this for loop for (var i = 0; i < bodyDelimiters.length; i++) { var aBodyDelimiter= bodyDelimiters[i]; print('Processing the following delimiter [' + aBodyDelimiter + '].'); var matcherClass = Java.type("java.util.regex.Matcher"); var quotedBody = matcherClass.quoteReplacement(modifiedBody); var pattern = Java.type("java.util.regex.Pattern").compile(aBodyDelimiter, regexpFlags); var matcher = pattern.matcher(quotedBody); if(matcher.find()) { var startIndex = matcher.start(); //If the expression applied to the body(comment or summary of the issue) results in empty then prevent the expression from applying (determine if you want this behaviour NOTE: if comment is empty then no comment is added to the issue.) if(startIndex === 0) { print('Body Delimiter expression [' + aBodyDelimiter + '] would remove all content! Ignoring this Delimiter') } //Actually applying the expression to the body else { print('Body Delimiter expression [' + aBodyDelimiter + '] was applied!') var sub = quotedBody.substring(0, startIndex); if(quotedBody.length() > body.length()) { sub = quotedBody.replace("\\\\", "\\").replace("\\$", "$"); } modifiedBody = sub; //condition for create and commenting remove either/none depending on your requirements if(relatedIssue) { resultMap.put("comment", modifiedBody); } else { result.put("summary", modifiedBody); } print('[' + aBodyDelimiter + '] result was [' + modifiedBody + ']'); } } } |
...