Text Workbench Online Help Submit feedback on this topic   

Regular Expression Laboratory

See Also
Regular Expression Syntax
Using Regular Expressions





If you are not familiar with regular expressions and want to learn how to use them, or want to test your own expressions, the Regular Expression Laboratory will help you much. Its main intent is to visualise both the internals of the expression compilation process and how the prepared expression matches the text portions.

At the heart of the regular expression engine is a concept of a finite-state automata. You can treat this automata as a tiny virtual computer working by a program. The program that the automata runs is the precompiled binary form of an expression. In other words, the textual expression that you provide is first compiled into a binary form and then executed against a text.

This is why you get regular expression errors sometimes. Some applications may even crash if the regular expression faults are not handled properly. Using the Regular Expression Laboratory, you will easily get a robust working expression.

You can open the Laboratory by clicking button in the Files and Text main window tab or Scenario Editor.

The following picture illustrates the Regular Expression Laboratory front-end.

How to Use the Laboratory

Using it is fairly simple. What is more, the Laboratory provides you with visual cues when you are mistaken with your expression. The below given sequence is usually the best practice.

  1. Type your text to operate on in the Sample text field. As an alternative, you can load the text from file by clicking the button Sample text.
  2. Type your expression in the Search pattern field. For example, if you want to match all HTML tags, you could type \<[^\>]#\> 
  3. Click the Match button. This will compile the expression and find the first occurrence of the matching text in the Sample text field. If the compilation fails, the erratic search expression symbol will blink with red.
  4. Type the replacement text in the Replace pattern box. For example, if you want to convert the HTML tag to lowercase: \L\0
  5. Click the Apply button. The result text box will contain the result of the replace operation.

Dialog Fields

The tables below describe the dialog fields.

Field Description
 Search pattern text box Contains the search expression.

 Search pattern
button



Shows a menu with regular expressions that you can select and insert.

 Multiline editor
button



Click this button to open the Multiline Editor dialog. This dialog allows entering text with multiple lines in normal mode, converting line breaks to \r and \n as appropriate.
 Match button Compiles the provided expression and tries to match it against the sample text. Click this button again to find the next match in the sample text. You can press and hold this button to iterate through the text.
 Sample text box Contains the sample text that the expression will match against.

 Sample text
button



Allows to load the sample text from file.
 Highlight stored expressions If checked, the matching stored expressions, i.e. those enclosed in parentheses ( ) will have different background colour in the sample text box.
 Replace pattern text box Contains the replacement expression.

 Replace pattern
button



Shows a menu with regular expressions that you can select and insert.

 Multiline editor
button



Same purpose as for the Multiline editor button for the Search pattern.
 Apply button Given the replacement expression, performs the replace operation on the sample text.