EVOLUTION-MANAGER
Edit File: re_match.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: Extract Regular Expression Matches Into a Data Frame</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 re_match {rematch2}"><tr><td>re_match {rematch2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract Regular Expression Matches Into a Data Frame</h2> <h3>Description</h3> <p><code>re_match</code> wraps <code><a href="../../base/html/regexpr.html">regexpr</a></code> and returns the match results in a convenient data frame. The data frame has one column for each capture group if <code>perl=TRUE</code>, and one final columns called <code>.match</code> for the matching (sub)string. The columns of the capture groups are named if the groups themselves are named. </p> <h3>Usage</h3> <pre> re_match(text, pattern, perl = TRUE, ...) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>text</code></td> <td> <p>Character vector.</p> </td></tr> <tr valign="top"><td><code>pattern</code></td> <td> <p>A regular expression. See <code><a href="../../base/html/regex.html">regex</a></code> for more about regular expressions.</p> </td></tr> <tr valign="top"><td><code>perl</code></td> <td> <p>logical should perl compatible regular expressions be used? Defaults to TRUE, setting to FALSE will disable capture groups.</p> </td></tr> <tr valign="top"><td><code>...</code></td> <td> <p>Additional arguments to pass to <code><a href="../../base/html/regexpr.html">regexpr</a></code>.</p> </td></tr> </table> <h3>Value</h3> <p>A data frame of character vectors: one column per capture group, named if the group was named, and additional columns for the input text and the first matching (sub)string. Each row corresponds to an element in the <code>text</code> vector. </p> <h3>Note</h3> <p><code>re_match</code> uses PCRE compatible regular expressions by default (i.e. <code>perl = TRUE</code> in <code><a href="../../base/html/regexpr.html">regexpr</a></code>). You can switch this off but if you do so capture groups will no longer be reported as they are only supported by PCRE. </p> <h3>See Also</h3> <p>Other tidy regular expression matching: <code><a href="re_exec_all.html">re_exec_all</a>()</code>, <code><a href="re_exec.html">re_exec</a>()</code>, <code><a href="re_match_all.html">re_match_all</a>()</code> </p> <h3>Examples</h3> <pre> dates <- c("2016-04-20", "1977-08-08", "not a date", "2016", "76-03-02", "2012-06-30", "2015-01-21 19:58") isodate <- "([0-9]{4})-([0-1][0-9])-([0-3][0-9])" re_match(text = dates, pattern = isodate) # The same with named groups isodaten <- "(?<year>[0-9]{4})-(?<month>[0-1][0-9])-(?<day>[0-3][0-9])" re_match(text = dates, pattern = isodaten) </pre> <hr /><div style="text-align: center;">[Package <em>rematch2</em> version 2.1.2 <a href="00Index.html">Index</a>]</div> </body></html>