explain function

Visualize Regular Expressions

Visualize Regular Expressions

Visualize regular expressions using https://regexper.com/

explain( pattern, open = FALSE, print = TRUE, dictionary = getOption("regex.library") )

Arguments

  • pattern: A character string containing a regular expression or a character string starting with "@" that is a regular expression from a qdapRegex dictionary.
  • open: logical. If TRUE the default browser will attempt to open https://regexper.com/ page. Setting open = 2 will utilize an unstable visualization via https://www.debuggex.com. This approach utilizes a non-api scrape that is subject to change and not guaranteed to be stable. The regex is set to Python flavor which handles lookbehinds that the Java based https://regexper.com/ does not. This functionality was developed by Matthew Flickinger (see https://stackoverflow.com/a/27574103/1000343 for details). Note that the user must have httr installed or will be prompted if the package cannot be required.
  • print: logical. Should explain print output to the console?
  • dictionary: A dictionary of canned regular expressions to search within.

Returns

Prints https://regexper.com/ to the console, attempts to open the url to the visual representation provided by https://regexper.com/, and invisibly returns a list with the URLs.

Details

Note that https://regexper.com/ is a Java based regular expression viewer. Lookbehind and negative lookbehinds are not respected.

Examples

explain("\\s*foo[A-Z]\\d{2,3}") explain("@rm_time") ## Not run: explain("\\s*foo[A-Z]\\d{2,3}", open = TRUE) explain("@rm_time", open = TRUE) ## End(Not run)

References

https://stackoverflow.com/a/27489977/1000343

https://regexper.com/

https://stackoverflow.com/a/27574103/1000343

See Also

https://regexper.com/

Author(s)

Ananda Mahto, Matthew Flickinger, and Tyler Rinker tyler.rinker@gmail.com.

  • Maintainer: Tyler Rinker
  • License: GPL-2
  • Last published: 2025-03-24