🕵 RegExplain

정규표현식을 R스튜디오 Add-in을 통해 쉽게 사용할 수 있는 패키지 

RegExr.com에서 영감을 받은 RegExplain는 정규 표현식을 위한 RStudio Add-in 패키지 입니다. 대화식으로 정규 표현식을 작성하고, 일반적인 문자열 일치 함수의 출력을 확인합니다.

설치 방법

devtools 를 통해 아래와 같이 설치하시면 됩니다.

devtools::install_github("gadenbuie/regexplain")

RegExplain 실행 화면

개요

RegExplain Selection

RegExplain 선택

Regular Expressions 라이브러리

RegExplain Library

RegExplain Library

Try the Built-In Examples

RegExplain Examples

RegExplain Examples

RStudio Addin

이 패키지의 주요 기능은 RStudio AddinRegExplain Selection 입니다.
텍스트가 들어있는 개체 (예 : 벡터 또는 data.frame 열의 변수 이름)를 선택하고 RStudio Addins 드롭 다운에서RegExplain Selection을 실행하면됩니다.

regexplain in the Rstudio Addins dropdown
Addin은 가져온 텍스트를 편집 할 수있는 4 개의 창으로 된 인터페이스를 엽니다.

  • 정규식을 구축하고 대화식으로 텍스트에 적용되는지 확인
  • base and stringr 패키지에서 일반적인 문자열 일치 및 대체 함수의 출력 테스트
  • 유용한 치트 시트를 참조

정규식을 구축하고 대화식으로 텍스트에 적용되는지 확인합니다.
base와 stringr에서 일반적인 문자열 일치 및 대체 함수의 출력 테스트
유용한 치트 시트를 참조하십시오.
 The panes of regexplain
When you’re done, click on the Send Regex to Console to send your regex expression to… the console!

> pattern <- "\\b(red|orange|yellow|green|blue|purple|white|brown)(?:\\s(\\w+))?"

Notice that RegExplain handled the extra backslashes needed for storing the RegEx characters \b\s, and \w. Inside the gadget you can use regular old regular expressions as you found them in the wild (hello, Stack Overflow!).

Help and Cheat Sheet

The Help tab is full of resources, guides, and R packages and includes an easy-to-navigate reference of commonly used regular expression syntax.
 regexplain help windows
Open RegExplain Cheatsheet from the RStudio Addins drop down to open the regex reference page in the Viewer pane without blocking your current R session.

Import Your Text

There are two ways to get your text into RegExplain. The first way was described above: select an object name or lines of text or code in the RStudio source pane and run RegExplain Selection. To import text from a file, use RegExplain File to you import the text you want to process with regular expressions.
When importing text, RegExplain automatically reduces the text to the unique entries and limits the number of lines.
 regexplain addins

Regular Expressions Library

The RegExplain gadget includes a regular expressions library in the RegEx tab. The library features common regular expressions, sourced from qdapRegex and Regex Hub, with several additional patterns.
The full library is stored as a JSON file in inst/extdata/patterns.json, feel free to contribute patterns you find useful or use regularly via pull request.
 regexplain library modal

View Static Regex Results

RegExplain provides the function view_regex() that you can use as a stringr::str_view()replacement. In addition to highlighting matched portions of the text, view_regex() colorizes groups and attempts to colorize 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 a bit of a labyrinth. For now, assume any issues or oddities you experience with this addin are entirely my fault and have nothing to do with the fine packages this addin is built on. If you do find an issue, please file an issue. Pull requests are welcomed!

출처: 🕵 RegExplain · Garrick Aden-Buie