Git Product home page Git Product logo

rex's Introduction

Rex

Build Status codecov.io Lifecycle: stable

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 bit longer than their corresponding regular expression, they are much more readable and maintainable.

Installation

install.packages("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.

rex's People

Contributors

jimhester avatar kevinushey avatar robertzk avatar ironholds avatar jackwasey avatar salim-b avatar yutannihilation avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.