Interactive Regular Expression Tool

Version 3.1.1 (222 KB) by Stephen23
Develop and refine regular expressions in an interactive figure that shows all of REGEXP's outputs.
Updated 25 Nov 2023

View License

IREGEXP is a simple interactive tool to help develop regular expressions. IREGEXP lets you interactively write regular expressions and see REGEXP's outputs update as you type.
IREGEXP consists of just one M-file which creates a figure containing two edit-boxes (for the input text and a regular expression) and that displays all of REGEXP's outputs inside the figure (note that the column widths can be adjusted manually).
IREGEXP can be used in two ways (and in any combination of these two ways):
  1. interactively by typing directly into the figure's edit-boxes, or
  2. by calling the function with exactly the same inputs and options as REGEXP itself.
Simply keep the figure open to use any combination of these two modes of operation: this allows for refining of the regular expression by changing the parse and regular expression strings, and also updating any REGEXP options that are supplied as function inputs. Text can be copied and pasted both to and from the two edit-boxes. If required, REGEXP's output values can be returned by calling the function with the appropriate output specifiers (by default there are no function outputs).
Keep It Simple
IREGEXP is intended to be the simplest interactive regular expression tool on FEX: no highlighting, no links, no colors, no buttons, no java code, no file parsing, no apps to install, no third-party dependencies... just this one M-file is all you need. IREGEXP aids fast development of a regular expression, especially by allowing editing using only the keyboard (use the tab key to switch between the edit-boxes), to parse short pieces of text.
MATLAB's UICONTROL text edit-boxes do not update as you type, so I used a little keypress-hack to try and achieve this. This hack does get easily confused, so to ensure that the correct text is being parsed you will need to enter the text properly: clicking away from the edit-box, as per MATLAB's UICONTROL documentation, is the only way to guarantee this!
Also note that in multiline mode the edit-box itself removes trailing newline characters from the text (not my code!).
Ellipses indicate continuation without closing the figure window.
% Call with the default parse and regular expression strings:
>> iregexp()
% ...interactively add the parse string '0_AAA111-BB22.CCCC3'.
% ...interactively add the regular expression '([A-Z]+)'.
% to set a new parse string:
>> iregexp('0_aaa111-BB22.cccc3',[])
% ...interactively change the regular expression to '([a-z]+)\d+'.
% to allow case-insensitive matching:
>> iregexp([],[],'ignorecase')
% ...interactively change the regular expression to '(?<str>[A-Z]+)(?<num>\d+)'.
% to assign selected outputs to some variables:
>> [A,B,C,D] = iregexp([],[],'ignorecase','match','start','tokens','split')
A = {'aaa111', 'BB22', 'cccc3'}
B = [3, 10, 15]
C = {{'aaa','111'},{'BB','22'},{'cccc','3'}}
D = {'0_','-','.',''}

Cite As

Stephen23 (2024). Interactive Regular Expression Tool (, MATLAB Central File Exchange. Retrieved .

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

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes

* Fix bug in token display with 'once' option.
* Improve documentation.


* Display string outputs with "".
* Return string outputs as string.
* Add HTML examples.


* Allow string class input arguments.
* Improve pretty-print local functions.


* Added fix suggested by Zhuohe Liu.


* Simplify code with UITABLE (replacing multiple UICONTROL text boxes).

* rename function.
* try to make HG2 compatible (needs testing).
* simplify internal handling of output arguments.

* Display outputs in edit boxes (as these have scrollbars).
* Input string can change ParseString edit box to multi-line.