Table of Contents

Glob - Globbing (Wildcard expression)

About

Glob is NOT a regular language but is wildly used to define a set of filenames with wildcard characters.

For instance, Bash provide globbing on filenames.

Wildcard / Syntax

The syntax is different by implementation and below are the most known pattern.

Asterix

An asterisk (also known as star) , *, matches any number of characters (including none).

Example:

Double Asterix

Two asterisks, **, works like * but crosses directory boundaries (ie complete paths) in a file system.

Example:

src/**/*.c

Syntax and parsing rule: if the two asterisks, ** are followed by a /, this pattern will match only directories and subdirectories. See globstar in bash

**/

Question mark

A question mark, ?, matches exactly one character.

Example:

Braces

Braces specify a collection of subpatterns. For example:

Square brackets

Square brackets convey a set of single characters or, when the hyphen character (-) is used, a range of characters.

Example:

Escape

To match *, ?, or the other special characters, you can escape them by using the backslash character, \. For example:

Note: If you are typing the glob pattern at the console and it contains one of the special characters, you must:

Definition

A possible definition is that a string is a wildcard pattern when it contains one of the characters

Language

globbing in other languages

Bash

See filename expansion example

Node

Java

Documentation / Reference