Intro | ||
Kiki is a free environment for regular expression testing (ferret).
It allows you to write regexes and test them against your sample
text, providing extensive output about the results. It is useful
for several purposes:
| ||
Working with Kiki | ||
Enter the regex in the combo box and hit Evaluate to run it against
the text in the Sample text tab. The results appear in the
Matches tab. You can use the list in the Help tab to view
the built-in documentation about regular expressions. This documentation
comes from the Python help files.
Kiki automatically stores its settings and the last used sample text/regex in between sessions. During a session, all regexes which have been evaluated and have returned matches, are also stored in the combo box where the regex is entered, so you may experiment with e.g. adapted versions without losing a more primitive regex that already kinda works. | ||
Options | ||
| ||
Understanding the output | ||
Kiki's output is quite extensive and provides color-coded information on the results
of the match. Let's assume you're trying to match the regex
fer(re)*t against
the sample text
Kiki the ferret - as nifty as ferrets get .
The results of a Find all evaluation by default looks something like this:
Each match is prepended by a small, underlined number: this is the index of the corresponding match object in the list of match objects found in the sample text. In the example above, there are two match objects, with indexes 0 and 1. Within each match, colored parentheses show where a match group starts and ends. Group ()0 represents the entire match. In this example we have also created an extra group because of the use of (re)* ". This is made visible by the green parentheses bearing the
index 1:
()1.
Pay attention to an interesting property of these groups: some of them might not contribute to the match and are then skipped in the output (in the match object, these groups start and end at position -1). An example: let's find all sentences talking about expecting the Spanish Inquisition in the text below:
Chapman: I didn't expect a kind of Spanish Inquisition.
For this purpose, we can use e.g. the following regex: ([a-zA-Z']+\s)+?expect(.*?)(the )*Spanish Inquisition(!|.)
The result is:
The interesting part is what's going on in the match with index 0: between the group with index 2 and the one with index 4, the group with index 3 has disappeared. This group matches an optional the which
is not present in this case. In other words, the group exists, but does not contribute
to the match and is therefore not displayed.
|