Match Regular Expressions with a Nicer 'API'

A small wrapper on 'regexpr' to extract the matches and captured groups from the match of a regular expression to a character vector.


A small wrapper on 'regexpr' to extract the matches and captured groups from the match of a regular expression to a character vector.

source("https://install-github.me/MangoTheCat/rematch")
library(rematch)
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)
#>      .match                       
#> [1,] "2016-04-20" "2016" "04" "20"
#> [2,] "1977-08-08" "1977" "08" "08"
#> [3,] NA           NA     NA   NA  
#> [4,] NA           NA     NA   NA  
#> [5,] NA           NA     NA   NA  
#> [6,] "2012-06-30" "2012" "06" "30"
#> [7,] "2015-01-21" "2015" "01" "21"
isodaten <- "(?<year>[0-9]{4})-(?<month>[0-1][0-9])-(?<day>[0-3][0-9])"
re_match(text = dates, pattern = isodaten)
#>      .match       year   month day 
#> [1,] "2016-04-20" "2016" "04"  "20"
#> [2,] "1977-08-08" "1977" "08"  "08"
#> [3,] NA           NA     NA    NA  
#> [4,] NA           NA     NA    NA  
#> [5,] NA           NA     NA    NA  
#> [6,] "2012-06-30" "2012" "06"  "30"
#> [7,] "2015-01-21" "2015" "01"  "21"

MIT © Mango Solutions

News

1.0.1

  • Make R CMD check work when testthat is not available.

  • Fixed a bug with group capture when text is a scalar.

1.0.0

First public release.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rematch")

1.0.1 by Gabor Csardi, 2 years ago


https://github.com/MangoTheCat/rematch


Report a bug at https://github.com/MangoTheCat/rematch/issues


Browse source code at https://github.com/cran/rematch


Authors: Gabor Csardi


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests covr, testthat


Imported by cellranger, rhub.


See at CRAN