- Notifications
You must be signed in to change notification settings - Fork27
🔍 An RStudio addin slash regex utility belt
License
gadenbuie/regexplain
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
RegExplain is an RStudio addin slash utility belt for regularexpressions. Interactively build your regexp, check the output of commonstring matching functions, consult the interactive help pages, or usethe included resources to learn regular expressions. And more.
Inspired byRegExr.com andstringr::str_view()
.
Installation is easy withremotes
# install.packages("remotes")remotes::install_github("gadenbuie/regexplain")
The main feature of this package is the RStudio AddinRegExplainSelection. Just select the text or object containing text (such as thevariable name of a vector or a data.frame column) and runRegExplainSelection from the RStudio Addins dropdown.
You can also open the addin withregexplain_gadget()
. This allows youto pass text or a regular expression to the gadget, which is useful whenyou want to work with a regular expression in your code or environment.
regexplain_gadget(text_vector,"\\b(red|blue|green):\\d{3}")
The addin will open an interface with 4 panes where you can
- edit thetext you’ve imported
- build up aregex expression and interactively see it applied toyour text
- test theoutput of common string matching and replacementfunctions from
base
andstringr
- and refer to ahelpful cheatsheet
When you’re done, click on theSend Regex to Console to send yourregex expression to… the console!
>pattern<-"\\b(red|orange|yellow|green|blue|purple|white|brown)(?:\\s(\\w+))?"
Notice thatRegExplain handled the extra backslashes needed forstoring the RegEx characters\b
,\s
, and\w
. Inside the gadget youcan use regular old regular expressions as you found them in the wild(hello,StackOverflow!).
TheHelp tab is full of resources, guides, and R packages andincludes an easy-to-navigate reference of commonly used regularexpression syntax.
OpenRegExplain Cheatsheet from the RStudio Addins drop down to openthe regex reference page in the Viewer pane without blocking yourcurrent R session.
There are two ways to get your text intoRegExplain. The first way wasdescribed above: select an object name or lines of text or code in theRStudio source pane and runRegExplain Selection. To import textfrom a file, useRegExplain File to you import the text you want toprocess with regular expressions.
When importing text,RegExplain automatically reduces the text to theunique entries and limits the number of lines.
TheRegExplain gadget includes a regular expressions library in theRegEx tab. The library features common regular expressions, sourcedfromqdapRegex andRegexHub, with several additionalpatterns.
The full library is stored as a JSON file ininst/extdata/patterns.json, feel free tocontribute patterns you find useful or use regularly via pull request.
RegExplain provides the functionview_regex()
that you can use as astringr::str_view()
replacement. In addition to highlighting matchedportions of the text,view_regex()
colorizes groups and attempts tocolorize the regex expression itself as well.
text<- c("breakfast=eggs;lunch=pizza","breakfast=bacon;lunch=spaghetti","no food here")pattern<-"((\\w+)=)(\\w+).+(ch=s?p)"view_regex(text,pattern)
t_nested<-"anestedgroupwithingroupexample"r_nested<-"(a(nested)(group(within(group))(example)))"view_regex(t_nested,r_nested)
Regular expressions are nothing if not a collection of corner cases.Trying to pass regular expressions through Shiny and HTML inputs is abit of a labyrinth. For now, assume any issues or oddities youexperience with this addin are entirely my fault and have nothing to dowith the fine packages this addin is built on. If you do find an issue,please file an issue. Pullrequests are welcomed!
About
🔍 An RStudio addin slash regex utility belt
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors3
Uh oh!
There was an error while loading.Please reload this page.