EVOLUTION-MANAGER
Edit File: re_exec_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 Data From All Regular Expression Matches Into a Data...</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_exec_all {rematch2}"><tr><td>re_exec_all {rematch2}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Extract Data From All Regular Expression Matches Into a Data Frame</h2> <h3>Description</h3> <p>Match a regular expression to a string, and return matches, match positions, and capture groups. This function is like its <code><a href="re_match_all.html">match</a></code> counterpart, except it returns match/capture group start and end positions in addition to the matched values. </p> <h3>Usage</h3> <pre> re_exec_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 entries within the match records within the list columns will be one vectors as long as there are matches for the corresponding text 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>Extracting Match Data</h3> <p>To make it easier to extract matching substrings or positions, a special <code>$</code> operator is defined on match columns, both for the <code>.match</code> column and the columns corresponding to the capture groups. See examples below. </p> <h3>See Also</h3> <p><code><a href="../../base/html/gregexpr.html">gregexpr</a></code>, which this function wraps </p> <p>Other tidy regular expression matching: <code><a href="re_exec.html">re_exec</a>()</code>, <code><a href="re_match_all.html">re_match_all</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" ) # All occurrences allpos <- re_exec_all(notables, name_rex) allpos # Custom $ to extract matches and positions allpos$first$match allpos$first$start allpos$first$end </pre> <hr /><div style="text-align: center;">[Package <em>rematch2</em> version 2.1.2 <a href="00Index.html">Index</a>]</div> </body></html>