preMatch Function

Purpose

Compiles a regular expression into an internal format.

Syntax

x$ = preMatch(pattern$)

x$:svar
pattern$ : Regular expression

Description

The preMatch function converts pattern into an internal format for faster execution. This allows for more efficient use of regular expressions in loops. The string containing the internal format is used as a pattern in reMatch, reSub, or Split. The internal format is identified by four leading bytes "]"#4#2"]".

Example

OpenW 1

Local a$, p$

p$ = preMatch(" ?ieter")

While _Data

Read a$

If reMatch(a$, p$)

Print a$

End If

Wend

Data "Harold","Dieter","Wolfgang","Erhard","Pieter"

Remarks

An overview of the regular expression pattern can be found in the topic reMatch.

Known Issues

preMatch("?ieter") causes an error as the function does not seem to like the '?' to be the first character; you can get round this by placing a space (which is then ignored) in front of the leading '?' as in the example above.

See Also

reMatch, reSub, Split

{Created by Sjouke Hamstra; Last updated: 21/10/2014 by James Gaite}