From 1a14bf3ef8c875c8e7dbd4308e9022c1b05dca57 Mon Sep 17 00:00:00 2001 From: dotasek Date: Tue, 13 Jun 2023 17:30:33 -0400 Subject: [PATCH] Lookahead based regex --- .../hl7/fhir/validation/cli/utils/AsteriskFilter.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/AsteriskFilter.java b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/AsteriskFilter.java index 1e203b7fe..12adfe535 100644 --- a/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/AsteriskFilter.java +++ b/org.hl7.fhir.validation/src/main/java/org/hl7/fhir/validation/cli/utils/AsteriskFilter.java @@ -6,15 +6,18 @@ import java.io.IOException; public class AsteriskFilter implements FilenameFilter { + public static final String EXPRESSION_REGEX = "(.+(?>\\\\|/))*(.*)"; + + public static final String DIR_REGEX = EXPRESSION_REGEX + "\\*(.*)"; String dir; String regex; public AsteriskFilter(String filter) throws IOException { - if (!filter.matches("(.*(\\\\|\\/))*(.*)\\*(.*)")) + if (!filter.matches(DIR_REGEX)) throw new IOException("Filter names must have the following syntax: [directorypath][prefix]?*[suffix]? I.e. The asterisk must be in the filename, not the directory path"); - dir = filter.replaceAll("(.*(\\\\|\\/))*(.*)\\*(.*)", "$1"); - String expression = filter.replaceAll("(.*(\\\\|\\/))*(.*)", "$3"); + dir = filter.replaceAll(DIR_REGEX, "$1"); + String expression = filter.replaceAll(AsteriskFilter.EXPRESSION_REGEX, "$2"); regex = ""; for (int i = 0; i < expression.length(); i++) { if (Character.isAlphabetic(expression.codePointAt(i)) || Character.isDigit(expression.codePointAt(i)))