EVOLUTION-MANAGER
Edit File: glob2rx.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Change Wildcard or Globbing Pattern into Regular Expression</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for glob2rx {utils}"><tr><td>glob2rx {utils}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Change Wildcard or Globbing Pattern into Regular Expression</h2> <h3>Description</h3> <p>Change <em>wildcard</em> aka <em>globbing</em> patterns into the corresponding regular expressions (<code><a href="../../base/html/regex.html">regexp</a></code>). </p> <h3>Usage</h3> <pre> glob2rx(pattern, trim.head = FALSE, trim.tail = TRUE) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>pattern</code></td> <td> <p>character vector</p> </td></tr> <tr valign="top"><td><code>trim.head</code></td> <td> <p>logical specifying if leading <code>"^.*"</code> should be trimmed from the result.</p> </td></tr> <tr valign="top"><td><code>trim.tail</code></td> <td> <p>logical specifying if trailing <code>".*$"</code> should be trimmed from the result.</p> </td></tr> </table> <h3>Details</h3> <p>This takes a wildcard as used by most shells and returns an equivalent regular expression. <code>?</code> is mapped to <code>.</code> (match a single character), <code>*</code> to <code>.*</code> (match any string, including an empty one), and the pattern is anchored (it must start at the beginning and end at the end). Optionally, the resulting regexp is simplified. </p> <p>Note that now even <code>(</code>, <code>[</code> and <code>{</code> can be used in <code>pattern</code>, but <code>glob2rx()</code> may not work correctly with arbitrary characters in <code>pattern</code>. </p> <h3>Value</h3> <p>A character vector of the same length as the input <code>pattern</code> where each wildcard is translated to the corresponding regular expression. </p> <h3>Author(s)</h3> <p>Martin Maechler, Unix/sed based version, 1991; current: 2004</p> <h3>See Also</h3> <p><code><a href="../../base/html/regex.html">regexp</a></code> about regular expression, <code><a href="../../base/html/grep.html">sub</a></code>, etc about substitutions using regexps. </p> <h3>Examples</h3> <pre> 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..$", glob2rx("*[*") == "^.*\\[" ) </pre> <hr /><div style="text-align: center;">[Package <em>utils</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>