Code covered by the BSD License  

Highlights from
regexpBuilder

3.5

3.5 | 2 ratings Rate this file 21 Downloads (last 30 days) File Size: 857 KB File ID: #41899
image thumbnail

regexpBuilder

by

 

22 May 2013 (Updated )

regexpBuilder is GUI that aims to simplify the creation of regexps in Matlab.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information
Description

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.

Usage:
   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);

Acknowledgements

Regexp Helper and Find J Obj Find Java Handles Of Matlab Graphic Objects inspired this file.

Required Products MATLAB
MATLAB release MATLAB 7.13 (R2011b)
Other requirements Note that older versions of Matlab have increasingly fewer capabilities in the regexp command. I've tried to make regexpBuilder version compliant, but I do not have older versions to test. Let me know in the comments if it doesn't work.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (9)
05 Jun 2013 Francis B.

After testing on 2013a this is very helpful.

04 Jun 2013 Francis B.

Thanks Mike. I appreciate the help.

04 Jun 2013 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.

04 Jun 2013 Francis B.

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

04 Jun 2013 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)

03 Jun 2013 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.

01 Jun 2013 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

29 May 2013 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!

23 May 2013 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.

Updates
24 May 2013

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.

03 Jun 2013

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

05 Jun 2013

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

30 Jul 2013

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.

19 Aug 2013

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

16 Oct 2013

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.

Contact us