Learn R Programming

sfsmisc (version 0.9-4)

glob2rx: 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)

Arguments

pattern
character vector

Value

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

See Also

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

Examples

Run this code
stopifnot(glob2rx("abc.*") == "^abc\\.",          glob2rx("a?b.*") == "^a.b\\.",
          glob2rx("*.doc") == "^.*\\.doc$",
          glob2rx("*.t*")  == "^.*\\.t",
          glob2rx("*.t??") == "^.*\\.t..$")

Run the code above in your browser using DataLab