# Using the QuickREx View for testing and evaluating regular expressions

- The QuickREx View
- Testing Regular Expressions
- Time-out and offline evaluation
- Selecting the Reg-Exp implementation
- Setting global compiler-flags
- Using TAB-completion
- Using the Reg-Exp-Edit dialog
- Copying Regular Expressions to Java-code
- Extracting all matches from text

## The QuickREx View

If the Plugin is installed, you should find a view named QuickREx offered under Window > Show View > Other... in the category QuickREx.

The view looks as displayed in the screenshot below.

The cool-bar icons are detailed in the following screenshot.

### Testing Regular Expressions

As you type text into the test-text area or a regular expression into the area for the regular expressions, the expression is constantly evaluated. The information on matches and groups is updated on the fly and matches are highlighted in the test-text.

Below is a screenshot of a situation where there are no groups but several matches. The match highlighted in green is the current one. All information on groups pertains to the current match.

The information next to the buttons used to navigate between the matches is to be interpreted as "There are 7 matches altogether, the current match (highlighted in green) has a start-index of 2 and an end-index of 4". As you can see there are no groups in the current match. You can navigate between the matches using the 'Previous' and 'Next' buttons near the label 'Matches'. If there were groups in the current match, you could navigate through the groups using the 'Previous' and 'Next' buttons near the label 'Groups'.

The above screenshot displays a case where there are groups in the current match. The current group is indicated by a bold font and the contents of the group are printed in the information-are next to the group-navigation buttons. The information there is to be interpreted as "There are 2 groups in the current match, the current group is the first one, containing 'the plugin evaluates '".

### Time-out and offline evaluation

As of Version 3, evaluation of the regular expression can be done offline by unsetting the mark at 'Live-evaluation' and using the 'Evaluate'-button if evaluation is in order.

Also from Version 3 on, evaluation of the regular expression takes place in a separate thread and may be cancelled by the user or is automatically cancelled if it takes too long. The dialog for cancelling the evaluation appears with a small delay so that you will not notice it during fast live-evaluation.

The time-out behaviour is configurable from the preference page available under 'Window > Preferences...' in the category 'QuickREx'. The preference page is displayed with the default settings in the screenshot below.

### Selecting the Reg-Exp implementation

QuickREx offers the most widely used implementations of Regular Expressions in the Java-world:

- JDK Regular Expressions (available since 1.4)
- Jakarta ORO Perl-style Regular Expressions (ORO-Version 2.0.8, supports Perl 5.003 Regular Expressions)
- Jakarta ORO Awk-style Regular Expressions (ORO-Version 2.0.8)
- JRegex Regular Expressions (Version 1.2_01, supports Perl 5.6 Regular Expressions)
- Jakarta Regexp Regular Expressions (Version 1.4)

The default implementation is the JDK-one. To change the implementation, use the leftmost buttons in the view's coolbar (see screenshot above). The expression will immediatly be re-evaluated. Also, the TAB-completion will adjust to offer the completions defined for the selected implementation.

Alternatively, you may use the view's drop-down menu and select the implementation of your choice (see figure).

### Setting global compiler-flags

You can set global compiler flags with any of the implementations QuickREx offers. This is done at the bottom of the view (see screenshot at the top of the page). To keep the view small, the "Global Flags"-section is folded away when the view is opened. To access it, click on the section-header.

The state of the flags is saved when you close the view or leave the Workbench. Note that there are different flags depending on the chosen implementation. Also note that the flags do behave slightly differently, depending on the implementation chosen. Check the tool-tip texts for the check-boxes to find details about the individual flags (see screenshot).

### Using TAB-completion

As in several specialized editors within Eclipse, you can use TAB-completion for regular expressions in QuickREx. To get a list of proposals for completion of the current expression, hit 'Ctrl+Space' while editing in the area for regular expressions. An assistant will open as displayed in the below screenshot. Scrolling through the suggestions also updates the hint on the right side of the proposal. When you select a proposal, QuickREx will try to work out whether the already typed in characters should be part of an expression or not.

Note that due to the complexity of regular expressions, TAB-completion is not as accurate as it is e.g. in the Java-editor. Sometimes the proposed possibilities may result in illegal patterns. Generally, QuickREx tries to do a good job in guessing what you may want. To this end, the rules are roughly as follows:

- Offer all completions which are not definitely illegal. Thus for example, you will not be offered '+' ("Greedy match 1 or more times") at the beginning of the regular expression - but almost anything else.
- Try to guess the intentions of the user in cases where things are pretty clear. Offer things starting with the most likely ones. They are the exceptions, but there are cases where it is clear what the user is after. Thus, the input '\p{Lo' is very likely part of '\p{Lower}'. This will be the first offer.
- In case there are several potential completions even within the rules, offer the shortest ones first. Thus, if you start with '\' and ask for completion, you will be offered '\\', '\0', ... before \p{Lower}. If you keep typing and the next character typed is a 'p', you will notice how the order of proposals changes.

### Using the Reg-Exp-Edit dialog

If you prefer a dialog with selection-lists and some bracket-highlighting over the combo to edit the regular expression, click the 'Edit...'-button to the right of the combo for the regular expression. The dialog displayed in the following figure will open:

The dialog differs for the different flavours, since they offer different options for multiplicities, wildcards, etc.

The text-field at the top of the dialog is used to type the regular expression. As you change the expression, the plug-in-view updates and the expression is evaluated against the current test-text (assuming you use live-evaluation). The text-field also offers some bracket-highlighting.

For expressions like wildcards etc, you will find the most commonly used options in the drop-down-lists. Whenever a list-entry is selected, the field at the bottom of the dialog displays a short explanation. If you want to use an expression, press 'Insert' next to the drop-down. The expression will be inserted at the current edit-position of the regular expression.

### Copying Regular Expressions to Java-code

Typically, regular expressions are full with backslashes and the like. To use them in code, you need to escape special characters. When the number of backslashes increases, this gets annoying. To simplify the task and to reduce the potential sources of errors, QuickREx offers the possibility of properly escaping the current regular expression and inserting them at the current curser position of (or replacing the current selection in) the last active editor window. To this end, simply place the cursor where you want the regular expression to go in the editor and press 'Copy to Java' in the coolbar or select it in the drop-down (see above).

### Grep - extracting all matches from text

If you want to extract only the matches for a particular regular expression from the current test-text, simply press the button 'Grep' in the coolbar or select it in the drop-down (see above). A dialog as displayed below will open, holding all matches separated by line-feeds. You can copy the result from the dialog to the clipboard to use it anywhere else as usually.