API-Version: 1.9

Glob

Globs are similar to regular expressions but much simpler, can be used for pattern matching. They only match against wildcard * and joker ? where the wildcard character matches any number of unknown characters and the joker matches exactly one unkown character. Note that internally regular expressions are used, so Glob matching is not faster than RegExp matching.

new Glob(pattern)

Constructs a new Glob

Parameters:
Name Type Description
pattern String

The pattern to match against

Source:
Example
 
var g = new Glob("foo*ba?baz");

Methods

exec(string) → {String}

Searches for the first occurence of the pattern in a string and returns the match.

Parameters:
Name Type Description
string String

The string to search for the pattern

Source:
Returns:

The match or null if the pattern wasn't found

Type
String
Example
 
var glob = new Glob("l*si?");
glob.exec("Melosine"); // "losin"

match(text) → {Boolean}

Match against a text

Parameters:
Name Type Description
text String

The text to match against

Source:
Returns:

true if the pattern was found

Type
Boolean
Example
 
var glob = new Glob("foo*ba?");
glob.match("foobarbaz");       // true
glob.match("foobaz");          // true
glob.match("foobarbazx");      // false
glob.match("fooba");           // false

Searches for the first occurence of the pattern in a string and returns the position.

Parameters:
Name Type Description
string String

The string to search for the pattern

Source:
Returns:

The first occurence or -1 if the pattern was not found

Type
Number
Example
 
var glob = new Glob("l?si*");
glob.search("Melosine"); // 2

toString() → {String}

Converts a glob to string

Source:
Returns:

The original pattern passed to the constructor

Type
String