Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/rexPublic

Friendly regular expressions for R.

License

NotificationsYou must be signed in to change notification settings

r-lib/rex

Repository files navigation

Codecov test coverageLifecycle: stableR-CMD-check

Friendly Regular Expressions

Regular expressions are very powerful feature, however they are often difficultto interpret. Rex allows you to build complex regular expressions from humanreadable 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 regularexpression, they are much more readable and maintainable.

Installation

install.packages("rex")

Usage

The vignettes have longer form usage examples.

Eachrex() 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 withinrex()calls, but they can be temporarily attached usingrex_mode() which allowsthem to be auto-completed.

Using Rex in other packages

Usingrex in other packages will generate spurious NOTEs fromR CMD checkunless you include a call torex::register_shortcuts() with your package namesomewhere in your package source. This function registers all of the rexshortcuts as valid variables fixing the NOTEs.

See Also

  • Regularity - Ruby library thatpartially inspiredrex.
  • PCRE - Perl Compatible Regular Expressions, theengine thatrex regular expressions use.
  • Perl 5 Regular Expressions - Perlregular expression documentation, which are nearly 100% compatible with PCRE.

About

Friendly regular expressions for R.

Resources

License

Stars

Watchers

Forks

Contributors11

Languages


[8]ページ先頭

©2009-2025 Movatter.jp