1 package com.explosion.utilities.regex;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.io.File;
24 import java.io.FilenameFilter;
25 import java.util.regex.Matcher;
26 import java.util.regex.Pattern;
27
28 public class RegExpFileNameFilter implements FilenameFilter
29 {
30
31 private Pattern pattern;
32
33 private boolean caseSensitive = false;
34
35 public RegExpFileNameFilter(String fileNamePattern, boolean caseSensitive)
36 {
37 this.caseSensitive = caseSensitive;
38 if (caseSensitive)
39 pattern = Pattern.compile(fileNamePattern);
40 else
41 pattern = Pattern.compile(fileNamePattern.toUpperCase());
42 }
43
44 public boolean accept(File parent, String filename)
45 {
46 Matcher m = null;
47 if (caseSensitive)
48 m = pattern.matcher(filename);
49 else
50 m = pattern.matcher(filename.toUpperCase());
51 return m.find();
52 }
53 }