rex v1.1.2

0

Monthly downloads

0th

Percentile

Friendly Regular Expressions

A friendly interface for the construction of regular expressions.

Readme

Rex

Build Status codecov.io

Friendly Regular Expressions

Regular expressions are very powerful feature, however they are often difficult to interpret. Rex allows you to build complex regular expressions from human readable expressions. So instead of writing (and later trying to decipher)

r <- "^(?:(((?:[^:])+)://))?((?:(?:(?!:/).)*)+)(?:(:([[:digit:]]+)))?(?:(/.*))?$"

You can write

r <- rex(

  start,

  ## match the protocol -- may exist or may not
  maybe(capture(
      capture(except_some_of(":")),
      "://"
      )),

  ## match the path
  capture(one_or_more(not(":/"))),

  ## get the port
  maybe(capture(":", capture(numbers))),

  ## and the rest
  maybe(capture("/", anything)),

  end

)

While these expressions are a big longer than their corresponding regular expression, they are much more readable and maintainable.

Installation

library(devtools)
install_github("kevinushey/rex")

Usage

The vignettes have longer form usage examples.

Each rex() function call can include a number of functions and shortcuts. For a full list of the functions available please see ?rex and ?shortcuts.

Rex Mode

Rex functions are not exported because they are only useful within rex() calls, but they can be temporarily attached using rex_mode() which allows them to be auto-completed.

Using Rex in other packages

Using rex in other packages will generate spurious NOTEs from R CMD check unless you include a call to rex::register_shortcuts() with your package name somewhere in your package source. This function registers all of the rex shortcuts as valid variables fixing the NOTEs.

See Also

  • Regularity - Ruby library that partially inspired rex.
  • PCRE - Perl Compatible Regular Expressions, the engine that rex regular expressions use.
  • Perl 5 Regular Expressions - Perl regular expression documentation, which are nearly 100% compatible with PCRE.

Functions in rex

Name Description
group Create a grouped expression
lookarounds Lookarounds
as.regex Coerce objects to a regex.
capture Create a capture group
single_shortcuts Single shortcuts
wildcards Wildcards
counts Counts
escape Escape characters for a regex
rex_mode Toggles rex mode.
shortcuts Shortcuts
not Do not match
%or% Or
re_substitutes Substitute regular expressions in a string with another string.
as.character.regex Regular Expression
%>% Pipe operator
re_matches Match function
character_class Create character classes
character_class_escape Character class escapes
register_shortcuts Register the Rex shortcuts
rex Generate a regular expression.
No Results!

Vignettes of rex

Name
NASA.txt
log_parsing.Rmd
stackoverflow.R
url_parsing.Rmd
No Results!

Last month downloads

Details

Type Package
URL https://github.com/kevinushey/rex
BugReports https://github.com/kevinushey/rex/issues
License MIT + file LICENSE
VignetteBuilder knitr
Collate 'aaa.R' 'utils.R' 'escape.R' 'capture.R' 'character_class.R' 'counts.R' 'lookarounds.R' 'match.R' 'or.R' 'rex-mode.R' 'rex.R' 'shortcuts.R' 'wildcards.R' 'zzz.R'
RoxygenNote 6.0.1.9000
NeedsCompilation no
Packaged 2017-10-19 19:22:40 UTC; jhester
Repository CRAN
Date/Publication 2017-10-19 19:54:00 UTC

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/rex)](http://www.rdocumentation.org/packages/rex)