\HeaderA{glob2rx}{Change Wildcard or Globbing Pattern into Regular Expression}{glob2rx}
\keyword{file}{glob2rx}
\keyword{character}{glob2rx}
\keyword{utilities}{glob2rx}
\begin{Description}\relax
Change \emph{wildcard} aka \emph{globbing} (or \dQuote{ls} like)
pattern into the corresponding regular expression (\code{\LinkA{regexp}{regexp}}).
\end{Description}
\begin{Usage}
\begin{verbatim}
glob2rx(pattern, trim.head = FALSE, trim.tail = TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{pattern}] character vector
\item[\code{trim.head}] logical specifying if leading \code{"\textasciicircum{}.*"} should be
trimmed from the result.
\item[\code{trim.tail}] logical specifying if trailing \code{".*\$"} should be
trimmed from the result.
\end{ldescription}
\end{Arguments}
\begin{Value}
a character vector of the same length as the input \code{pattern}
where the \dQuote{wild card} is translated to the corresponding
regular expression.
\end{Value}
\begin{Author}\relax
Martin Maechler, Unix/sed based version, 1991; current: 2004
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{regexp}{regexp}} about regular expression,
\code{\LinkA{sub}{sub}}, etc about substitutions using regexps.
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
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..$"
)
\end{ExampleCode}
\end{Examples}

