3 min read

R Regex Tester Shiny App

This post is to announce a shiny app I’ve written to test regular expressions in an R environment.

If you’re not interested in reading any commentary on the motivation & features, here’s a link to the app on shinyapps.io. If you use the app and have any issues please report them to the app’s github repo (also please leave a ★ if you like the app!)


Why?

This is definitely not the first online regex tester, and it’s not the most fully featured. The main reasons for developing this were:

  1. Testing in an R environment (I would always have to double my backslashes after working out a regex in another tester)
  2. A fun/challenging side project that involved shiny
  3. And of course to have the chance to help somebody out if they find the app useful

Features

Options

  • The other 2 options concerning backslashes allow you to write an R flavored regex.
    • For example, if you want to match a literal period with a regex you’ll type “\\.” (as if you were writing the regex in R).
    • If you don’t like this behavior, and you’d rather type half of the slashes needed to make the regex functional in R, you can select the “Auto Escape Backslashes” option for “Pattern” and then use “\.” to match literal periods in the app.

Input

  • There are 2 text inputs:
    1. Matching Pattern: type the regular expression or fixed pattern here that you want to use to match against your text.
    2. Test String: type the text that you want your Matching Pattern to search through

Results

  • After the pattern and test string are entered we see 2 different versions of the resulting pattern matching:
    1. The test string is shown with the matches/capture groups highlighted where they appear in the text
      • As noted in the UI, currently nested capture group highlighting isn’t supported. If our matching pattern was “t(e(s))(t)” the highlighting wouldn’t display correctly.
    2. The second output is a bulleted list of the matches and capture groups found in our test string. In the screen shot below we see we matched 2 instances of “test”, and each of these matches display below them the contents of the 2 capture groups we included in our regex pattern.

Regex Explanation

  • There’s additionally a collapsable panel that will do it’s best to break down your regex and explain the components. As noted in the UI these explanations are provided by rick.measham.id.au
  • The screen shot below shows the explanation for our regex: “t(es)(t)”

Helping Documentation

  • The app includes some documentation for using regular expressions in R. The two including pieces of helping documentaion are:
    1. The RStudio Regex Cheatsheet
    2. The base R documentation on regex (this is what would appear if you ran the command ?regex)

Extra

Shiny’s bootstrap roots allow apps to transition between desktop and mobile pretty seamlessly. The app’s mobile experience isn’t terrible, so you can use it for all your regex-ing fun on the go! (I won’t ask why)