Character escaping, The wild card operators: ? and – Crunch CRiSP File Editor 6 User Manual

Page 48

Advertising
background image

Page 48

<, %, ^

matches the beginning of a line.

>, $

matches the end of a line.

?

matches any single character.

*

matches zero or more characters

[..]

matches any character within the [..]

\c

used to set the cursor after a match.

\n

Matches the newline character at the end of a line.

\<

Match beginning of line or non-word character.

\>

Match end of line or non-word character.

Two regular expressions juxtaposed allow
concatenation.

An implied precedence is used with these characters, and it may be necessary to use the '\x' character to
avoid certain characters being treated as special characters.

Technically, a regular expression consists of a sequence of one or more simple expressions. A simple
expression (SE) is one of the following:

a sequence of characters
< or ^ or %
> or $
[..]
?
*

A simple regular expression (SRE) is a simple expression, optionally followed or enclosed in a modifier:

{SE}
SE@
SE+
SE

A regular expression is a sequence of simple regular expressions as follows:

SRE SRE

(Concatenation)

SRE | SRE

(Alternation)

Character Escaping

The backslash character may be used to precede any character to turn off any special effects the character
has. For example to match an asterisk in the text, the sequence "\*" would be used.

A common form of error when writing macros is to forget that the macro compiler strips off the first level of
backslash characters. For example, if the user wants to match an asterisk in a macro, he/she might write:

search_fwd("\*");

However, this is wrong. The macro compiler strips off the '\' and leaves the expression as "*" which matches
every line. In order to escape this character properly, the following should be used:

search_fwd("\\*");

In this case, the macro compiler strips off the first backslash leaving "\*" for the regular expression parser to
translate.

The wild card operators: ? and *

The '?' operator matches a single character; '*' matches zero or more characters.

The number of characters matched by a '*' depends on what follows the '*' and the search mode. The
Minimal and Maximal(pg. 50). matching section describes the issues relating to the length of a matched
string.

Advertising