Vrex - A Visual Regular Expression Tool

Introduction

I have used Visual Regexp by Laurent Riesterer. It is a tool for constructing and testing regular expressions written in Tcl/Tk. I found it quite useful when writing the p2t.py script for PAGE.

Since I was debugging a new version of PAGE at the time, I decided that I would rewrite a subset of Visual Regexp in Python. My program is called 'vrex'. The reasons for writing it were (1) it thought it would be a good example of PAGE that would illustrate several important usages of tkinter - especially the application of different colored text in a text box. (2) Since Visual Regexp is a Tcl/Tk script it utilizes the Tcl regular expression processor which is necessarily different from the Python regular expression support and so a python programmer should test his regular expressions using the python regular expression support. (3) Visual Regexp has absolutely no documentation which is disgraceful but all too common with open source software. Since I wrote the python tool, I know how it works and can document it as I am doing here. This program is based on Visual Regexp and even uses the same colorization algorithm.

Visual Regexp provides a mechanism for creating the candidate regexp. However, I never figured out how it works (no documentation) so I couldn't put it in my program.

Requirements

All that is needed is Python 2.7. Or if you are using Python 3.1 that is all that is needed.

Installation

Merely download vrex.tgz and untar it with

tar -zxvf vrex.tgz
The following command will execute the program:
python vrex.py

Usage

The program GUI looks like:
.

  1. One enters the regular expression under test into the top text box, and the sample which is the subject of the regular expression match into the middle text box. One may use the File menu to load files into the text boxes, one may directly type entries or use the normal cut and paste facilities of the operating system.
  2. Pressing the Go button causes the match to be attempted. Also, colorization is applied to both the regular expression and to the sample. The regular expression is colorized to show the portions of the regular expression are to extracted individually. And if the match is successful the corresponding portions of the sample are displayed in the same colors.
  3. By selecting one of the row of buttons marked match, 1, 2, ..., 9, the portions of the sample corresponding to extracted portions are displayed in the match window.
  4. You can use the File menu to load to save both the regular expression and the sample.
  5. The Quit Button terminates the program.
  6. The File menu also has a Quit entry that terminates the program.

In normal usage, one loads a sample and a regular expression and experiments with incrementally changes both and testing by hitting the go button. When you are satisfied you can save the regular expression or put it on the clipboard by selecting the characters that make up the regular expression.

You can also enter a whole file of sample strings using File->Load Sample. In that case, when you select Go, the regular expression candidate will be applied to each line individually in the sample and the sample will be colorized accordingly. Obviously, you can add build a set of samples by adding them to the sample window and saving the sample to a file.