README.md

Rust Regex in R

This Rust implementation of regular expressions guarantees linear time performance.

It can handle both untrusted regular expressions and untrusted search text.

Benchmark

subject <- paste(rep("a", N), collapse="")
pattern <- paste(rep(c("a?", "a"), each=N), collapse="")

benchmark

Install

Rust >= 1.8

devtools::install_github("rustr/rsegex")

Match

library(rsegex)

reg = regex("a")

re_match(reg, c("aa","b","aasdads"))

#> [1]  TRUE FALSE  TRUE

Replace

reg = regex("(?P<last>[^,\\s]+),\\s+(?P<first>\\S+)")

input = "Springsteen, Bruce"

re_replace(reg, input, "$first $last")

#> [1] "Bruce Springsteen"

Split

reg = regex("[ \\t]+")
re_split(reg, c("a b    c    d    e","sd ssd    s"))

#> [[1]]
#> [1] "a" "b" "c" "d" "e"
#> 
#> [[2]]
#> [1] "sd"  "ssd" "s"  

Capture

reg = regex("(?x)
(?P<year>\\d{4})  # the year
-
(?P<month>\\d{2}) # the month
-
(?P<day>\\d{2})   # the day
")

captures_len(reg)

#> [1] 4

captures_names(reg)

#> [1] ""      "year"  "month" "day"  



rustr/rsegex documentation built on May 28, 2019, 10:41 a.m.