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.
install.packages("rex")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 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.
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.
rex.rex regular expressionsuse.