glob2rx {utils}R Documentation

Change Wildcard or Globbing Pattern into Regular Expression

Description

Change wildcard aka globbing (or “ls” like) pattern into the corresponding regular expression (regexp).

Usage

glob2rx(pattern, trim.head = FALSE, trim.tail = TRUE)

Arguments

pattern character vector
trim.head logical specifying if leading "^.*" should be trimmed from the result.
trim.tail logical specifying if trailing ".*$" should be trimmed from the result.

Value

a character vector of the same length as the input pattern where the “wild card” is translated to the corresponding regular expression.

Author(s)

Martin Maechler, Unix/sed based version, 1991; current: 2004

See Also

regexp about regular expression, sub, etc about substitutions using regexps.

Examples

stopifnot(glob2rx("abc.*") == "^abc\\.",
          glob2rx("a?b.*") == "^a.b\\.",
          glob2rx("a?b.*", trim.tail=FALSE) == "^a.b\\..*$",
          glob2rx("*.doc") == "^.*\\.doc$",
          glob2rx("*.doc", trim.head=TRUE) == "\\.doc$",
          glob2rx("*.t*")  == "^.*\\.t",
          glob2rx("*.t??") == "^.*\\.t..$"
)

[Package utils version 2.2.1 Index]