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

🔍 An RStudio addin slash regex utility belt

License

NotificationsYou must be signed in to change notification settings

gadenbuie/regexplain

Repository files navigation

Regular expressions are tricky. RegExplainmakes it easier to see what you’re doing.

Project Status: Active – The project has reached a stable, usable state and is being actively developed.CRAN_Status_Badge

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

Installation is easy withremotes

# install.packages("remotes")remotes::install_github("gadenbuie/regexplain")

RegExplain in Action

Overview

regexplain selection

Regular Expressions Library

regexplain library

Try the Built-In Examples

regexplain examples

RStudio Addin

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.

regexplain in 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 frombase andstringr
  • and refer to ahelpful cheatsheet

The panes of regexplain

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!).

Help and Cheat Sheet

TheHelp tab is full of resources, guides, and R packages andincludes an easy-to-navigate reference of commonly used regularexpression syntax.

regexplain help windows

OpenRegExplain Cheatsheet from the RStudio Addins drop down to openthe regex reference page in the Viewer pane without blocking yourcurrent R session.

Import Your Text

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.

regexplain addins

Regular Expressions Library

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 library modal

View Static Regex Results

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)

Example view_regex(text, pattern).

t_nested<-"anestedgroupwithingroupexample"r_nested<-"(a(nested)(group(within(group))(example)))"view_regex(t_nested,r_nested)

Example of nested groups

Notes

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!

Packages

No packages published

Contributors3

  •  
  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp