Class GlobPattern
- java.lang.Object
-
- com.microstrategy.web.app.utils.GlobPattern
-
public final class GlobPattern extends java.lang.Object
Glob pattern is specified as a string and is matched against other strings, such as directory or file names.Glob syntax follows several simple rules:
An asterisk,
*
, matches any number of characters (including none).Two asterisks,
**
, works like*
but crosses directory boundaries.A question mark,
?
, matches exactly one character.Braces { } specify a collection of subpatterns. For example:
- {one,two,three} matches "one", "two", or "three".
- {temp*,tmp*} matches all strings beginning with "temp" or "tmp".
Square brackets
[ ]
convey a set of single characters or, when the hyphen character-
is used, a range of characters. Within the square brackets,*
,?
, and\
match themselves. For example:[0-9]
matches any digit.[A-Z]
matches any uppercase letter.[a-z,A-Z]
matches any uppercase or lowercase letter.
All other characters match themselves.
To match
*
,?
, or the other special characters, you can escape them by using the backslash character,\
. For example:\\
matches a single backslash.
- See Also:
FileSystem.getPathMatcher(String)
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static GlobPattern
compile(java.lang.String pattern)
Compiles the given glob pattern.boolean
matches(java.lang.CharSequence input)
Tells if given input matches this pattern.static boolean
matches(java.lang.String pattern, java.lang.CharSequence input)
Compiles the given glob pattern and attempts to match the given input against it.java.lang.String
pattern()
Returns the glob pattern from which this pattern was compiled.
-
-
-
Method Detail
-
pattern
public java.lang.String pattern()
Returns the glob pattern from which this pattern was compiled.- Returns:
- The source of this pattern
-
compile
public static GlobPattern compile(java.lang.String pattern)
Compiles the given glob pattern.- Parameters:
pattern
- The pattern to be compiled- Returns:
- the given glob pattern compiled into a GlobPattern
- Throws:
java.util.regex.PatternSyntaxException
- If the pattern's syntax is invalid
-
matches
public boolean matches(java.lang.CharSequence input)
Tells if given input matches this pattern.- Parameters:
input
- The character sequence to be matched- Returns:
- whether or not the glob pattern matches on the input
-
matches
public static boolean matches(java.lang.String pattern, java.lang.CharSequence input)
Compiles the given glob pattern and attempts to match the given input against it.An invocation of this convenience method of the form
behaves in exactly the same way as the expressionGlobPattern.matches(pattern, input);
GlobPattern.compile(pattern).matches(input)
If a pattern is to be used multiple times, compiling it once and reusing it will be more efficient than invoking this method each time.
- Parameters:
pattern
- The glob pattern to be compiledinput
- The character sequence to be matched- Returns:
- whether or not the glob pattern matches on the input
- Throws:
java.util.regex.PatternSyntaxException
- If the pattern's syntax is invalid
-
-