MyNixOS website logo
Description

Friendly Regular Expressions.

A friendly interface for the construction of regular expressions.

Rex

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.
Metadata

Version

1.2.1

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows