File Exchange

image thumbnail


version (595 KB) by Michael Ryan
regexpBuilder is GUI that aims to simplify the creation of regexps in Matlab.


Updated 01 Jul 2015

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. A demo is provided, in the help, look under 'Other Demos' -> 'rexpBuilder Demo' -> 'regexpBuilder' -> 'Using the regexpBuilder GUI' in Matlab versions up to R2011b and in 'Supplemental Software' in R2012a and up.
Enter your regexp in the textbox with "Regexp goes here...".
Optional inputs to the regexp command are enabled using the
checkboxes below. An unchecked box signifies the default is used for
that option. The text to be run on goes in the textbox marked "Text
to parse goes here".

If you click the Evaluate button, check one of the option
checkboxes, or simply type in either the Regexp or Text textboxes,
the regexp is run against the text and the results are printed in
the Output panel on the right. Each box corresponds to the
particular output of the regexp command. For example, the Match
textbox will contain the same information as [match] =
regexp(text,regexp,...,'match'), with the addition of the phrase
'Match #:' signifying which match it corresponds to. You can click
on the button with the Match label to obtain a bigger window for
those results.

If the regexp can match the text, each match is underlined in the
text and the entire regexp is underlined. If the regexp contains
tokens (named or unnamed), the definition of each token is
highlighted in the regexp and every match of the token is
highlighted in the text with the matching color. Thus, for a regexp
with many tokens that matches often, your text might look rather
rainbowy. If you would like to change the color scheme, see the
highlightText function in this file.

Lastly, if the you click the Evaluate button, along with the output
mentioned above, the arguments to the regexp command used are
printed to the Command Window in the form
output = regexp(TEXT,REGEXP, ARGUMENTS);

Comments and Ratings (16)

Lorenzo C.

Hi!, Very useful tool, i just need to enlarge font size due desktop resolution.

Hi mike, i downloaded the latest files and updated. It now seems to be functional in 2015b, but yes, the buttons are a bit messed up.

Thanks for the update

Hi Mike,
here is the error i get in 2015b.

Warning: No Java reference was found for the requested handle, because the figure is still invisible in regexpBuilder_OutputFcn()
> In findjobj/warnInvisible (line 338)
In findjobj (line 314)
In regexpBuilder>regexpBuilder_OutputFcn (line 171)
In gui_mainfcn (line 264)
In regexpBuilder (line 73)
Undefined function 'getViewport' for input arguments of type 'handle.handle'.

Error in regexpBuilder>regexpBuilder_OutputFcn (line 172)
jText = jScrollPane.getViewport.getComponent(0);

Error in gui_mainfcn (line 264)
feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);

Error in regexpBuilder (line 73)
gui_mainfcn(gui_State, varargin{:});


If you do release an update, could you consider renaming the built-in Matlab functions that are being overridden so that it does not cause a name conflict for other tools, especially if this is on the path above the normal Matlab path? Or, you could see if the built-in functions serve the purpose now.

Built-in functions I've found include:

Thank you.

I do plan on updating, since at a minimum the panel/button arrangement is all messed up in 2016a. I don't have 2015b, and (besides the wonky buttons) it seems to be working in 2016a, so could you provide a bit more information on how it's crashing and what, if any errors are appearing?

this seems to crash in 2015b. are there plans to upgrade, because i love this tool.

Very helpful for building regular expression in MATLAB.

My default prior to using this tool was a regex builder on the web. However, the regex expression that I built was not always compatible with MATLAB. This tool avoids that problem because I am working directly in MATLAB.

Francis B.

After testing on 2013a this is very helpful.

Francis B.

Thanks Mike. I appreciate the help.

It does matter apparently. R2011a added the ability to perform empty matches, which I didn't realize. I've updated regexpBuilder to be more version compliant. Unfortunately, I do not have access to earlier versions, so I can't test it fully. Let me know if something breaks. Also, your regexp matches the 1GCEC14W9XE186XXX part.

Francis B.

Not sure if this matters but I am using Matlab 2010a

Francis B.

This is what I steps I have taken:

1. Open regexBuilder.m
2. Click Run function
3. Copy paste the following into 'Regexp goes here...': (?<=content="vin:)(.*?)(?=\")
4. Copy/paste the following into 'Text to parse goes here...': 'meta itemprop="productID" content="vin:1GCEC14W9XE186XXX"/>
<div class="yui3-u" id="nav">&nbsp;</div>
<div class="yui3-u" id="main">
<div class="vDetailTitleWrap clearfix">'
5. Click 'Evaluate'

(Thanks with any/all help)

I'm updating the description and help text to add a demo. (The update should appear soon.)
Could you explain the process that led to that warning? The error is a direct result of the call to regexp failing and a struct not being populated as a result. I've fixed that in the update, but 'noemptymatch' certainly is a correct (and default) option for regexp, so I'm a bit stumped.

Francis B.

Is there any information of a step-by-step process to use this builder? I been using (regexpHelper) and am verify that I have a appropriate search/input information. Any help would be much appreciated. Thanks!

I receive the following Error:

Warning: Invalid option for regexp: noemptymatch.
> In regexpBuilder>doRegexp at 508
In regexpBuilder>evaluate_Callback at 237
In gui_mainfcn at 96
In regexpBuilder at 69
In @(hObject,eventdata)regexpBuilder('evaluate_Callback',hObject,eventdata,guidata(hObject))
??? Reference to non-existent field 'start'.

Error in ==> regexpBuilder>doRegexp at 588

Error in ==> regexpBuilder>evaluate_Callback at 237
regexpCommand = doRegexp(handles);

Error in ==> gui_mainfcn at 96

Error in ==> regexpBuilder at 69
gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)regexpBuilder('evaluate_Callback',hObject,eventdata,guidata(hObject))

??? Error while evaluating uicontrol Callback

I have removed the setCaretPosition(caret) aspect. (I was trying to get the text boxes to update correctly as the user typed and was doing it in a very stupid way.) Any action that can be done in a normal text box is now allowed and should be correctly implemented. Let me know if anything else is broken!

Andreas J.

I really like this tool. but what i find rather annoying is the "hObject.setCaretPosition(caret);"

* you can't use CTRL+A
* after typing a character the cursor gets one to the left of the typed character. ~nearly every 2cd character entered the cursor moves left.


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.

MATLAB Release Compatibility
Created with R2011b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Discover Live Editor

Create scripts with code, output, and formatted text in a single executable document.

Learn About Live Editor