1
2
3
4
5
6
7 package org.abraracourcix.alipes.common;
8
9 /***
10 * This class generates regular expressions from simple wildcard expressions.
11 * For this class, wildcard expressions are expressions of the form
12 * "a*.txt" to match "a.txt, ab.txt.....
13 * or
14 * "abc.???" to match "abc.abc, abc.txt2 but not "abc.text"
15 * @author jdt
16 */
17 public final class RegExpCreator {
18 /***
19 *
20 * Constructor to hide public ctor
21 *
22 */
23 private RegExpCreator(){}
24 /***
25 * Given a wildcard expression return the corresponding regexp
26 * @param wildcard the wildcard
27 * @return the regexp
28 */
29 public static String getRegExp(final String wildcard) {
30
31
32
33
34
35
36 String regexp = wildcard.replaceAll("//.","////.").replace('?','.').replaceAll("//*",".*");
37 return regexp;
38 }
39 }
40
41
42
43
44
45
46
47
48
49
50