Interactive Regular Expression Tool

Versión 3.1.1 (222 KB) por Stephen23
Develop and refine regular expressions in an interactive figure that shows all of REGEXP's outputs.
1.7K descargas
Actualizado 25 Nov 2023

Ver licencia

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.
Important
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!).
Example
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]+)'.
% ...call to set a new parse string:
>> iregexp('0_aaa111-BB22.cccc3',[])
% ...interactively change the regular expression to '([a-z]+)\d+'.
% ...call to allow case-insensitive matching:
>> iregexp([],[],'ignorecase')
% ...interactively change the regular expression to '(?<str>[A-Z]+)(?<num>\d+)'.
% ...call 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_','-','.',''}

Citar como

Stephen23 (2024). Interactive Regular Expression Tool (https://www.mathworks.com/matlabcentral/fileexchange/48930-interactive-regular-expression-tool), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2010b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre String Parsing en Help Center y MATLAB Answers.

Community Treasure Hunt

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

Start Hunting!
Versión Publicado Notas de la versión
3.1.1

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

3.1.0

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

3.0.0

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

2.1.1

* Added fix suggested by Zhuohe Liu.

2.1.0

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

2.0.0.0

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

1.1.0.0

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

1.0.0.0