Appendix B. Glob pattern syntax and examples

 

Glob patterns are used by the Java 7 NIO.2 libraries for applying filters when iterating over directories and other similar tasks, as seen in chapter 2.

B.1. Glob pattern syntax

Glob patterns are simpler than regular expressions and follow the basic rules shown in table B.1.

Table B.1. Glob pattern syntax

Syntax

Description

* Matches zero or more characters.
** Matches zero or more characters across directories.
? Matches exactly one character.
{} Delimits a collection of subpatterns to match with an implicit OR for each pattern; e.g. matches pattern A or B or C etc.
[] Matches a single set of characters, or if a hyphen (-) character is used, matches a range of characters.
\ Escape character; used if you want to match a special character such as *, ?, or \.

Further information on glob pattern syntax can be found in the Java Tutorial hosted online by Oracle (http://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob) and in the Javadoc for the FileSystem class.

B.2. Glob pattern examples

Some basic examples on using glob patterns, sometimes known as globbing, are shown in table B.2.