regexpBuilder is GUI that aims to simplify the creation of regexps in Matlab.
Updated 5 Jun 2020

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

regexpBuilder() is GUI that aims to simplify the creation of regexps in Matlab. It shows exactly what the various outputs are for the given regexp, text, and input options as you type. All regexp constructs supported by Matlab are allowed, for help on regexps, see doc regexp. Note: regexpBuilder has been rebuilt from the ground up to work with R2020a and later!

Enter your regexp in the textbox with "Regexp goes here...".
Optional inputs to the regexp command are enabled using the toggle buttons; an unset button gives the default value for the option.
Add the text to be regex'd to the "Text to parse goes here..." box. (a preview of found matches will appear in the adjacent box.)
Press the evaluate button to see a preview of any matches below, as well as the values of the various possible outputs, on the left. (Bigger output windows can be obtained by clicking the corresponding button).

Imports and Exports There are 3 ways to import text into regexpBuilder:
Using the optional inputtxt parameter will prepopulate the input text box on startup.
Using the Import from URL button on the Import tab will pop up a window prompting a URL to import from. regexpBuilder uses webread to open URLs.
Using the Import from file will open a File Chooser dialog, select the file to import there. regexpBuilder uses fileread to open files.

The Export tab provides a way to export the final regexp command, as well as a variety of options for the export, generally corresponding to the output options for regexp. Note that only non-default options will be written to the command line.

Live Preview
If the regexp can match the text, each match is underlined in the right text box. If the regexp contains tokens (named or unnamed), every match of the token is highlighted in the text with the color corresponding to the token. Thus, for a regexp with many tokens that matches often, your text might look rather rainbowy. regexpBuilder uses the jet colorscheme, so you can change the colorscheme by shadowing the jet colormap.

I've only been able to test this on one machine/MATLAB version so far, so please let me know about any bugs in the comments!

Cite As

Michael Ryan (2024). regexpBuilder (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2020a
Compatible with R2020a and later releases
Platform Compatibility
Windows macOS Linux
Find more on Characters and Strings in Help Center and MATLAB Answers

Inspired by: RegexpHelper

Inspired: Interactive Regular Expression Tool

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Complete rewrite/update for R2020a and later using App Designer. Some GUI elements have changed, but the basic functionality should still be present.

Reduced startup time, improved visuals by using JIDE components. (Thanks!). Issue with resizing figure window, so that is currently disabled. Also, this has been tested on 2015a. Let me know about issues.

The R2014b graphics update introduced a few bugs. I've included the latest(3/23/2015) version of Yair Altman's findjobj.m as well as done some reordering of the ui components. Let me know if there are any further issues.

Updated to include the suggestions from the POTW article: Results boxes are no longer editable, added text import from files and URLs, UI placement tweaks.

Fixed bug introduced in previous version with dot matches newline option. Now changed to dot except newline.

Revised and added additional print command options. Now only prints the non-default options, unless specified otherwise, along with only the selected outputs. Updated help.

Added version compliance -> No empty match in ver<R2011a, no split in ver<R2007b, no ignore case, multiline, or freespacing in v<R2006a.

Updated some error handling with the regexp command. Added demo and updated description and help to reflect that.

Greatly improved the as-you-type parsing. I was doing something very stupid (with the setCaretPos stuff). It is now fixed: I no longer use setCaretPos, and Ctrl-A works correctly.