1% Generated by roxygen2: do not edit by hand 2% Please edit documentation in R/package.R 3\name{re_match} 4\alias{re_match} 5\title{Extract Regular Expression Matches Into a Data Frame} 6\usage{ 7re_match(text, pattern, perl = TRUE, ...) 8} 9\arguments{ 10\item{text}{Character vector.} 11 12\item{pattern}{A regular expression. See \code{\link[base]{regex}} for more 13about regular expressions.} 14 15\item{perl}{logical should perl compatible regular expressions be used? 16Defaults to TRUE, setting to FALSE will disable capture groups.} 17 18\item{...}{Additional arguments to pass to \code{\link[base]{regexpr}}.} 19} 20\value{ 21A data frame of character vectors: one column per capture 22 group, named if the group was named, and additional columns for 23 the input text and the first matching (sub)string. Each row 24 corresponds to an element in the \code{text} vector. 25} 26\description{ 27\code{re_match} wraps \code{\link[base]{regexpr}} and returns the 28match results in a convenient data frame. The data frame has one 29column for each capture group if \code{perl=TRUE}, and one final columns 30called \code{.match} for the matching (sub)string. The columns of the capture 31groups are named if the groups themselves are named. 32} 33\note{ 34\code{re_match} uses PCRE compatible regular expressions by default 35(i.e. \code{perl = TRUE} in \code{\link[base]{regexpr}}). You can switch 36this off but if you do so capture groups will no longer be reported as they 37are only supported by PCRE. 38} 39\examples{ 40dates <- c("2016-04-20", "1977-08-08", "not a date", "2016", 41 "76-03-02", "2012-06-30", "2015-01-21 19:58") 42isodate <- "([0-9]{4})-([0-1][0-9])-([0-3][0-9])" 43re_match(text = dates, pattern = isodate) 44 45# The same with named groups 46isodaten <- "(?<year>[0-9]{4})-(?<month>[0-1][0-9])-(?<day>[0-3][0-9])" 47re_match(text = dates, pattern = isodaten) 48} 49\seealso{ 50Other tidy regular expression matching: 51\code{\link{re_exec_all}()}, 52\code{\link{re_exec}()}, 53\code{\link{re_match_all}()} 54} 55\concept{tidy regular expression matching} 56