Skip to content

yzchang/Regexcite

Repository files navigation

NOTE: This is an example package mostly copied from the online edition of R Packages (2e). All credits go to the original authors.

Regexcite

The goal of Regexcite is to make regular expressions more exciting! It provides convenience functions to make some common tasks with string manipulation and regular expressions a bit easier.

Installation

You can install the development version of Regexcite from GitHub with:

# install.packages("devtools")
devtools::install_github("yzchang/Regexcite")

Usage

A fairly common task when dealing with strings is the need to split a single string into a plain list of many parts.

This package provides two functions Regexcite::str_split_one() and Regexcite::str_split_multi() that split a single character vector by a single character (i.e. Regexcite::str_split_one()) or one or more character vectors by one or more characters (i.e. Regexcite::str_split_multi()) into a single list of character vector(s).

Example

Use Regexcite::str_split_one() when the input is know to be a single string and the pattern is a single character:

library(Regexcite)
s <- "echo:foxtrot:golf:hotel"
str_split_one(s, ':')
#> [1] "echo"    "foxtrot" "golf"    "hotel"

Use Regexcite::str_split_multi() when the input contains multiple strings or the pattern contains multiple characters:

library(Regexcite)
fruits <- c(
  "apples and oranges and pears and bananas",
  "pineapples and mangos and guavas"
)
str_split_multi(fruits, " and ")
#> [[1]]
#> [1] "apples"     "pineapples" "oranges"    "mangos"     "pears"     
#> [6] "guavas"     "bananas"

About

Make Regular Expressions Easier

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages