EVOLUTION-MANAGER
Edit File: re_match_all.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 All 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_all {rematch2}"><tr><td>re_match_all {rematch2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract All Regular Expression Matches Into a Data Frame</h2> <h3>Description</h3> <p>This function is a thin wrapper on the <code><a href="../../base/html/gregexpr.html">gregexpr</a></code> base R function, to extract the matching (sub)strings as a data frame. It extracts all matches, and potentially their capture groups as well. </p> <h3>Usage</h3> <pre> re_match_all(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/gregexpr.html">gregexpr</a></code> (or <code><a href="../../base/html/regexpr.html">regexpr</a></code> if <code>text</code> is of length zero).</p> </td></tr> </table> <h3>Value</h3> <p>A tidy data frame (see Section “Tidy Data”). The list columns contain character vectors with as many entries as there are matches for each input element. </p> <h3>Tidy Data</h3> <p>The return value is a tidy data frame where each row corresponds to an element of the input character vector <code>text</code>. The values from <code>text</code> appear for reference in the <code>.text</code> character column. All other columns are list columns containing the match data. The <code>.match</code> column contains the match information for full regular expression matches while other columns correspond to capture groups if there are any, and PCRE matches are enabled with <code>perl = TRUE</code> (this is on by default). If capture groups are named the corresponding columns will bear those names. </p> <p>Each match data column list contains match records, one for each element in <code>text</code>. A match record is a named list, with entries <code>match</code>, <code>start</code> and <code>end</code> that are respectively the matching (sub) string, the start, and the end positions (using one based indexing). </p> <h3>Note</h3> <p>If the input text character vector has length zero, <code><a href="../../base/html/regexpr.html">regexpr</a></code> is called instead of <code><a href="../../base/html/gregexpr.html">gregexpr</a></code>, because the latter cannot extract the number and names of the capture groups in this case. </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.html">re_match</a>()</code> </p> <h3>Examples</h3> <pre> name_rex <- paste0( "(?<first>[[:upper:]][[:lower:]]+) ", "(?<last>[[:upper:]][[:lower:]]+)" ) notables <- c( " Ben Franklin and Jefferson Davis", "\tMillard Fillmore" ) re_match_all(notables, name_rex) </pre> <hr /><div style="text-align: center;">[Package <em>rematch2</em> version 2.1.2 <a href="00Index.html">Index</a>]</div> </body></html>