--> Class COM.stevesoft.pat.FileRegex
Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD


Class COM.stevesoft.pat.FileRegex

java.lang.Object
  |
  +--COM.stevesoft.pat.RegRes
        |
        +--COM.stevesoft.pat.Regex
              |
              +--COM.stevesoft.pat.FileRegex
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]$


Fields inherited from class COM.stevesoft.pat.Regex
dontMatchInQuotes, dotDoesntMatchCR, esc, ignoreCase
 
Fields inherited from class COM.stevesoft.pat.RegRes
charsMatched_, didMatch_, marks, matchFrom_, numSubs_, src
 
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()
           
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
accept, add, clone, compile1, compile, countMaxChars, countMinChars, define, define, getReplacer, getReplaceRule, isDefined, isLiteral, matchAt, optimized, optimize, perlCode, replaceAllFrom, replaceAll, replaceAllRegion, replaceFirstFrom, replaceFirst, replaceFirstRegion, result, searchFrom, search, searchRegion, setReplaceRule, setReplaceRule, toString, undefine, version
 
Methods inherited from class COM.stevesoft.pat.RegRes
charsMatched, charsMatched, clone, didMatch, equals, getString, left, left, matchedFrom, matchedFrom, matchedTo, matchedTo, matchFrom, matchFrom, numSubs, right, right, stringMatched, stringMatched, substring, substring, toString

 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Constructor Detail

FileRegex

public FileRegex()
Build an unitialized FileRegex.

FileRegex

public FileRegex(java.lang.String s)
Build a FileRegex form String s.
Method Detail

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#compile(java.lang.String)

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

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()
Overrides:
isLiteral in class Regex

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD