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!)
This is definitely not the first online regex tester, and it’s not the most fully featured. The main reasons for developing this were:
- Testing in an R environment (I would always have to double my backslashes after working out a regex in another tester)
- A fun/challenging side project that involved shiny
- And of course to have the chance to help somebody out if they find the app useful
- 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.
- There are 2 text inputs:
- Matching Pattern: type the regular expression or fixed pattern here that you want to use to match against your text.
- Test String: type the text that you want your Matching Pattern to search through
- After the pattern and test string are entered we see 2 different versions of the resulting pattern matching:
- 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.
- 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.
- 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)”
- The app includes some documentation for using regular expressions in R. The two including pieces of helping documentaion are:
- The RStudio Regex Cheatsheet
- The base R documentation on regex (this is what would appear if you ran the command
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)