TRE | |
Author: | Ville Laurikari[1] |
Programming Language: | C |
Genre: | Approximate string matching |
License: | 2-clause BSD-like license |
TRE is an open-source library for pattern matching in text,[2] which works like a regular expression engine with the ability to do approximate string matching.[3] It was developed by Ville Laurikari[1] and is distributed under a 2-clause BSD-like license.
The library[4] is written in C and provides functions which allow using regular expressions for searching over input text lines. The main difference from other regular expression engines is that TRE can match text fragments in an approximate way, that is, supposing that text could have some number of typos.
TRE uses extended regular expression syntax with the addition of "directions" for matching preceding fragment in approximate way. Each of such directions specifies how many typos are allowed for this fragment.
Approximate matching[5] is performed in a way similar to Levenshtein distance, which means that there are three types of typos 'recognized':[6]
Typo | Example | Data | |
---|---|---|---|
insertion of an extra character | extra l, extra e | ||
missing a character from pattern | missing u, missing r | ||
replacement of some character | u → o, s → z |
The project comes with a command-line utility, a reimplementation of agrep.
Though approximate matching requires some syntax extension, when this feature is not used, TRE works like most of other regular expression matching engines. This means that
The library's author states[8] that time spent for matching grows linearly with increasing of input text length, while memory requirement is constant during matching and does not depend on the input, only on the pattern.
Other features, common for most regular expression engines could be checked in regex engines comparison tables or in list of TRE features on its web-page.
Approximate matching directions are specified in curly brackets and should be distinguishable from repetitive quantifiers (possibly with inserting a space after opening bracket):
(expression){ 5i + 3d + 2s < 11}
would match word "expression" if total cost of typos is less than 11, while insertion cost is set to 5, deletion to 3 and substitution of character to 2 - i.e. gives cost of 10.Apart from C, TRE is usable through bindings for Perl, Python and Haskell.[9] It is the default regular expression engine in R.[10] However, if the project should be cross-platform, there would be necessary separate interface for each of the target platforms.
Since other regular expression engines usually do not provide approximate matching ability, there is almost no concurrent implementation with which TRE could be compared. However, there are a few things which programmers may wish to see implemented in future releases:[11]