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. However, I found two problems with the program. First, there was no documentation, and second, I felt that it had several significant design oversights (SDO's). I changed the program to correct the problems that I felt were most important and that version is now on the PAGE web site.

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. Finally, 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. I

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.

After writing vrex, I came across kodos which does very much the same things or more. It uses qt library in KDE.

Requirements

Since this program was developed with PAGE and uses a Tix widget, you will need Python and Tix installed. Installing Tix requires Tcl/Tk. The requirements are less demanding than for using PAGE, since tixwish is not required. Often, enough of Tcl/Tk and Tix are bundled with Python that no more is required.

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.

Variation from the PAGE Recommendations

You will notice that I varied from the recommendations that I gave in the PAGE User's Guide. There I suggested that (a) one doesn't specify colors and rely on the WmDefault package to provide colors consistent with the underlying window manager and (b) one doesn't specify fonts for the same reason.

However, I specified that the text window be white because I want the user to be able to recognize several different colors. I picked dark colors so I want there to always be a light background to facilitate the color differentiation.

For the same reason, I wanted a big bold font.

PAGE Home