com.stevesoft.pat
Class FileRegex
java.lang.Object
|
+--com.stevesoft.pat.RegRes
|
+--com.stevesoft.pat.Regex
|
+--com.stevesoft.pat.FileRegex
- All Implemented Interfaces:
- java.lang.Cloneable, java.io.FilenameFilter
- Direct Known Subclasses:
- DirFileRegex, NonDirFileRegex
- public class FileRegex
- extends Regex
This class is a different form of Regex designed to work more
like the file matching utility of a Unix shell. It is implemented
by some simple string transformations:
| FileRegex | Regex |
| * | .* |
| . | \. |
| { | (?: |
| {?! | (?! |
| {?= | (?= |
| {?? | (?? |
| } | ) |
| ? | . |
| {,} | (|) |
Note that a FileRegex pattern always ends with the Regex
pattern element "$". If you like to experiment, try making
FileRegex's and then printing them out. The toString() method
does a decompile of the pattern to a standard Regex. Here are
some more complete examples:
| FileRegex | Regex |
| *.java | .*\.java$ |
| *.{java,html} | .*\.(java|html)$ |
| foo.[chC] | foo.[chC]$ |
|
Constructor Summary |
FileRegex()
Build an unitialized FileRegex. |
FileRegex(java.lang.String s)
Build a FileRegex form String s. |
|
Method Summary |
boolean |
accept(java.io.File dir,
java.lang.String s)
This is the method required by FileNameFilter. |
void |
compile(java.lang.String s)
Compile a new pattern. |
boolean |
isLiteral()
Checks to see if there are only literal and no special
pattern elements in this Regex. |
static java.lang.String[] |
list(java.lang.String f)
Provides an alternative to File.list -- this
separates its argument according to File.pathSeparator. |
static java.lang.String |
toFileRegex(java.lang.String s)
This method takes a file regular expression, and translates it
into the type of pattern used by a normal Regex. |
| Methods inherited from class com.stevesoft.pat.Regex |
add,
clone,
compile1,
countMaxChars,
countMinChars,
define,
define,
equals,
getDefaultMFlag,
getDontMatchInQuotes,
getGFlag,
getIgnoreCase,
getMFlag,
getReplacer,
getReplaceRule,
getSFlag,
isDefined,
matchAt,
matchAt,
optimize,
optimized,
perlCode,
replaceAll,
replaceAll,
replaceAllFrom,
replaceAllRegion,
replaceFirst,
replaceFirstFrom,
replaceFirstRegion,
result,
reverseSearch,
reverseSearch,
search,
search,
searchFrom,
searchFrom,
searchRegion,
setDefaultMFlag,
setDontMatchInQuotes,
setGFlag,
setIgnoreCase,
setReplaceRule,
setReplaceRule,
toString,
undefine,
version |
| Methods inherited from class com.stevesoft.pat.RegRes |
charsMatched,
charsMatched,
copyOutOf,
didMatch,
equals,
getString,
getStringLike,
left,
left,
matchedFrom,
matchedFrom,
matchedTo,
matchedTo,
matchFrom,
matchFrom,
numSubs,
right,
right,
stringMatched,
stringMatched,
substring,
substring |
| Methods inherited from class java.lang.Object |
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
FileRegex
public FileRegex()
- Build an unitialized FileRegex.
FileRegex
public FileRegex(java.lang.String s)
- Build a FileRegex form String s.
compile
public void compile(java.lang.String s)
throws RegSyntax
- Compile a new pattern.
Throws @exception com.stevesoft.pat.RegSyntax for
nonsensical patterns like "[9-0]+" just as Regex does.
- Overrides:
- compile in class Regex
- See Also:
- com.stevesoft.pat
accept
public boolean accept(java.io.File dir,
java.lang.String s)
- This is the method required by FileNameFilter.
To get a listing of files in the current directory
ending in .java, do this:
File dot = new File(".");
FileRegex java_files = new FileRegex("*.java");
String[] file_list = dot.list(java_files);
- Overrides:
- accept in class Regex
- Tags copied from class: Regex
- See Also:
FileRegex
list
public static java.lang.String[] list(java.lang.String f)
- Provides an alternative to File.list -- this
separates its argument according to File.pathSeparator.
To each path, it splits off a directory -- all characters
up to and including the first instance of File.separator --
and a file pattern -- the part that comes after the directory.
It then produces a list of all the pattern matches on all
the paths. Thus "*.java:../*.java" would produce a list of
all the java files in this directory and in the ".." directory
on a Unix machine. "*.java;..\\*.java" would do the same thing
on a Dos machine.
toFileRegex
public static java.lang.String toFileRegex(java.lang.String s)
- This method takes a file regular expression, and translates it
into the type of pattern used by a normal Regex.
isLiteral
public boolean isLiteral()
- Description copied from class: Regex
- Checks to see if there are only literal and no special
pattern elements in this Regex.
- Overrides:
- isLiteral in class Regex