Lookahead based regex
This commit is contained in:
parent
3c7abb5eff
commit
1a14bf3ef8
|
@ -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)))
|
||||
|
|
Loading…
Reference in New Issue