Movatterモバイル変換


[0]ホーム

URL:


Rex

codecov.ioLifecycle: stable

Friendly Regular Expressions

Regular expressions are very powerful feature, however they are oftendifficult to interpret. Rex allows you to build complex regularexpressions from human readable expressions. So instead of writing (andlater trying to decipher)

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

You can write

r<-rex(  start,## match the protocol -- may exist or may notmaybe(capture(capture(except_some_of(":")),"://"      )),## match the pathcapture(one_or_more(not(":/"))),## get the portmaybe(capture(":",capture(numbers))),## and the restmaybe(capture("/", anything)),  end)

While these expressions are a bit longer than their correspondingregular expression, 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 offunctions and shortcuts. For a full list of the functions availableplease 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 allows them to be auto-completed.

Using Rex in other packages

Usingrex in other packages will generate spurious NOTEsfromR CMD check unless you include a call torex::register_shortcuts() with your package name somewherein your package source. This function registers all of the rex shortcutsas valid variables fixing the NOTEs.

See Also


[8]ページ先頭

©2009-2025 Movatter.jp