Interactive Regular Expression Tool

버전 3.1.1 (222 KB) 작성자: Stephen23
Develop and refine regular expressions in an interactive figure that shows all of REGEXP's outputs.
다운로드 수: 1.7K
업데이트 날짜: 2023/11/25

라이선스 보기

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_','-','.',''}

인용 양식

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

MATLAB 릴리스 호환 정보
개발 환경: R2010b
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
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