From 5503dbfffc10ef9f51da7c37cb66e933d747a874 Mon Sep 17 00:00:00 2001 From: deiflaender Date: Thu, 15 Sep 2022 13:03:21 +0200 Subject: [PATCH] RSS-105: Use string after match of first regEx for second regex in redactBetweenRegexes --- .../v1/server/redaction/model/Section.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 452ae5a3..779d8217 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 @@ -605,8 +605,15 @@ public class Section { @Argument(ArgumentType.BOOLEAN) boolean skipRemoveEntitiesContainedInLarger, @Argument(ArgumentType.BOOLEAN) boolean sortedResult) { - String startValue = getFirstRexExMatch(startPattern, startPatternCaseInsensitive, startGroup); - String stopValue = getFirstRexExMatch(stopPattern, stopPatternCaseInsensitive, stopGroup); + String startValue = getFirstRexExMatch(searchText, startPattern, startPatternCaseInsensitive, startGroup); + + if (startValue == null){ + return; + } + + String searchTextAfter = StringUtils.substringAfter(searchText, startValue); + + String stopValue = getFirstRexExMatch(searchTextAfter, stopPattern, stopPatternCaseInsensitive, stopGroup); if (startValue != null && stopValue != null) { redactBetween(startValue, stopValue, includeStart, includeStop, type, ruleNumber, false, false, reason, legalBasis, true, skipRemoveEntitiesContainedInLarger, sortedResult); @@ -1148,10 +1155,10 @@ public class Section { } - private String getFirstRexExMatch(String pattern, boolean patternCaseInsensitive, int group) { + private String getFirstRexExMatch(String text, String pattern, boolean patternCaseInsensitive, int group) { Pattern compiledPattern = Patterns.getCompiledPattern(pattern, patternCaseInsensitive); - Matcher matcher = compiledPattern.matcher(searchText); + Matcher matcher = compiledPattern.matcher(text); while (matcher.find()) { String match = matcher.group(group);