diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java index 9fce1fe9..452ae5a3 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/redaction/model/Section.java @@ -589,6 +589,31 @@ public class Section { } + @ThenAction + public void redactBetweenRegexes(@Argument(ArgumentType.STRING) String startPattern, + @Argument(ArgumentType.BOOLEAN) boolean startPatternCaseInsensitive, + @Argument(ArgumentType.INTEGER) int startGroup, + @Argument(ArgumentType.BOOLEAN) boolean includeStart, + @Argument(ArgumentType.STRING) String stopPattern, + @Argument(ArgumentType.BOOLEAN) boolean stopPatternCaseInsensitive, + @Argument(ArgumentType.INTEGER) int stopGroup, + @Argument(ArgumentType.BOOLEAN) boolean includeStop, + @Argument(ArgumentType.RULE_NUMBER) int ruleNumber, + @Argument(ArgumentType.TYPE) String type, + @Argument(ArgumentType.STRING) String reason, + @Argument(ArgumentType.STRING) String legalBasis, + @Argument(ArgumentType.BOOLEAN) boolean skipRemoveEntitiesContainedInLarger, + @Argument(ArgumentType.BOOLEAN) boolean sortedResult) { + + String startValue = getFirstRexExMatch(startPattern, startPatternCaseInsensitive, startGroup); + String stopValue = getFirstRexExMatch(stopPattern, stopPatternCaseInsensitive, stopGroup); + + if (startValue != null && stopValue != null) { + redactBetween(startValue, stopValue, includeStart, includeStop, type, ruleNumber, false, false, reason, legalBasis, true, skipRemoveEntitiesContainedInLarger, sortedResult); + } + } + + @Deprecated @ThenAction @SuppressWarnings("unused") @@ -1123,6 +1148,22 @@ public class Section { } + private String getFirstRexExMatch(String pattern, boolean patternCaseInsensitive, int group) { + + Pattern compiledPattern = Patterns.getCompiledPattern(pattern, patternCaseInsensitive); + Matcher matcher = compiledPattern.matcher(searchText); + + while (matcher.find()) { + String match = matcher.group(group); + if (StringUtils.isNotBlank(match)) { + return match; + } + } + + return null; + } + + private void redactBetween(String start, String stop, boolean includeStart, boolean includeStop, String asType, int ruleNumber, boolean redactEverywhere, boolean excludeHeadLine, String reason, String legalBasis, boolean redaction, boolean skipRemoveEntitiesContainedInLarger,