org.exist.util
Class GlobToRegex
java.lang.Object
org.exist.util.GlobToRegex
- public class GlobToRegex
- extends java.lang.Object
Translates a glob expression into a Java regular expression.
The following syntax is supported for glob expressions:
- * - Matches zero or more instances of any character. If the
STAR_CANNOT_MATCH_NULL_MASK option is used, * matches
one or more instances of any character.
- ? - Matches one instance of any character. If the
QUESTION_MATCHES_ZERO_OR_ONE_MASK option is used, ?
matches zero or one instances of any character.
- [...] - Matches any of characters enclosed by the brackets.
* and ? lose their special meanings within a
character class. Additionaly if the first character following
the opening bracket is a ! or a ^, then any
character not in the character class is matched. A -
between two characters can be used to denote a range. A
- at the beginning or end of the character class matches
itself rather than referring to a range. A ] immediately
following the opening [ matches itself rather than
indicating the end of the character class, otherwise it must be
escaped with a backslash to refer to itself.
- \ - A backslash matches itself in most situations. But
when a special character such as a * follows it, a
backslash escapes the character, indicating that
the special chracter should be interpreted as a normal character
instead of its special meaning.
- All other characters match themselves.
Please remember that the when you construct a Java string in Java code,
the backslash character is itself a special Java character, and it must
be double backslashed to represent single backslash in a regular
expression.
The original code is adapted from the jakarta ORO package.
Method Summary |
static java.lang.String |
globToRegexp(java.lang.CharSequence pattern)
This static method is the basic engine of the Glob PatternCompiler
implementation. |
static void |
main(java.lang.String[] args)
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
GlobToRegex
public GlobToRegex()
globToRegexp
public static java.lang.String globToRegexp(java.lang.CharSequence pattern)
- This static method is the basic engine of the Glob PatternCompiler
implementation. It takes a glob expression in the form of a character
array and converts it into a String representation of a Perl5 pattern.
The method is made public so that programmers may use it for their own
purposes. However, the GlobCompiler compile methods work by converting
the glob pattern to a Perl5 pattern using this method, and then invoking
the compile() method of an internally stored Perl5Compiler instance.
- Parameters:
pattern
- A character array representation of a Glob pattern.
- Returns:
- A String representation of a Perl5 pattern equivalent to the Glob
pattern.
main
public static void main(java.lang.String[] args)
- Parameters:
args
-
Copyright (C) Wolfgang Meier. All rights reserved.