File Exchange

image thumbnail

regexpBuilder

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

6 Downloads

Updated 05 Jun 2020

View Version History

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!

Usage:
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 (2021). regexpBuilder (https://www.mathworks.com/matlabcentral/fileexchange/41899-regexpbuilder), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (21)

Jason Nicholson

Jason Nicholson

Thank you for the update! I am glad to see this working again!

Chang hsiung

Josh Philipson

Hi Michael - This does not render properly in r2020a.

Warning: JAVACOMPONENT will be removed in a future release. For more information see UI Alternatives for MATLAB Apps on mathworks.com.
Warning: The JavaFrame figure property will be removed in a future release. For more information see UI Alternatives for MATLAB Apps on mathworks.co

Jogger

Which is the main file /function to used to run the program. I am using R2019a and getting the error .
Warning: No Java reference was found for the requested handle, because the figure is still invisible in regexpBuilder_OutputFcn()
> In findjobj/warnInvisible (line 417)
In findjobj (line 382)
In regexpBuilder>regexpBuilder_OutputFcn (line 183)
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 184)
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{:});

Lorenzo C.

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

Brian Wilson

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

Brian Wilson

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{:});

Aditya

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:
verLessThan

Thank you.

Michael Ryan

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?

Brian Wilson

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

Jason Nicholson

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.

Michael Ryan

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)

Michael Ryan

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
set(gui.('Start').handle,'String',rb.start);

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

Error in ==> gui_mainfcn at 96
feval(varargin{:});

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

Michael Ryan

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.

MATLAB Release Compatibility
Created with R2020a
Compatible with R2020a and later releases
Platform Compatibility
Windows macOS Linux
Acknowledgements

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!