Nombas Logo


Regexpsn

The regexpsn library allows you to perform complicated search routines with regular expressions (as in UNIX or Perl).

The process is pretty complicated. First you must allocate a space in memory with regGetHandle(), and then compile a search string pattern to search for with RegComp(). RegExec() is the function that actually performs the search.

The following operators have special meaning in search strings:

.

matches any single character except new line

x*

matches zero or more occurrences of the character x

x+

matches one or more occurrences of the character x

x?

matches zero or one occurrence of the character x

[&ldots;]

matches any of the characters inside the brackets

x{n}

matches exactly n occurrences of the character x

x{n,}

matches n or more occurrences of the character x

x{,m}

matches zero or at most m occurrences of the character x

x{n,m}

matches at least n occurrences, but no more than m occurrences of the character x

$

matches the end of a line

\0

matches the null character

\b

matches a backspace

\B

matches any character that's not at the beginning or at the end of a word

\b

matches the beginning or end of a word (when not inside brackets)

\cX

matches Ctrl - X

\d

matches a single digit

\D

matches a non-digit character

\f

matches a form feed

\n

matches a newline (line-feed) character

\ooo

matches an octal value specified by the digits ooo (where each o is a digit between 0 and 7)

\r

matches a carriage return

\S

matches a non-white-space character

\s

matches a white-space character (space, tab, or newline)

\t

matches a tab

\W

matches a non-alphanumeric character

\w

matches an alphanumeric character

\xhh

matches the hexadecimal value specified by the digits hh (where each h is a digit between 0 and f)

^

matches the beginning of a line

In addition, since the characters $, |, *, ^, [, ], / and \ have special meanings in code strings, you must put a backslash before them if you want to search for the character itself. In other words, to search for the * character, you would search for /*.

regGethandle

Allocates memory for a search pattern

SYNTAX:

int RegGetHandle(void);

COMMENTS

This function must be called first to initialize memory for the search string. The handle that is returned must then be used in subsequent calls to RegComp, RegExec, and RegError. The memory should be freed with a call to RegFree when you are done using it.

RETURN

Returns a handle to an area in memory.


To the Top of Page Nombas' homepage #link libraries

RegComp

Compiles search pattern

SYNTAX:

int RegComp(int handle, string searchpattern, int flags);

COMMENTS

handle is the handle returned by RegGetHandle.

Searchpattern is the string to be searched for. It may contain characters and operators as described in this section.

RETURN

0 if successful; otherwise, returns an integer which corresponds to an error message. This error message may be accessed with a call to RegError


To the Top of Page Nombas' homepage #link libraries

RegExec

Executes search

SYNTAX:

int RegExec(int handle, string searchtext, int numberOfMatches, matchArray, int flags);

COMMENTS

This function executes a search. The string pattern to search for must have been previously compiled with calls to RegGetHandle and RegComp.

handle is the handle returned by RegGetHandle and passed as the first parameter to RegComp.

searchtext is the string to be scanned for matching substrings

numberOfMatches is the number of matches to display. This should always be set to one.

RETURN

0 if successful; otherwise, returns an integer which corresponds to an error message. This error message may be accessed with a call to RegError

To the Top of Page Nombas' homepage #link libraries

RegError

Gets Error string

SYNTAX:

void RegError(int errornumber, int handle, string message [,messagesize])

COMMENTS

This message takes an error number (as returned by RegExec or RegComp) and translates it into a string describing said error. The message will be stored in the string message).


To the Top of Page Nombas' homepage #link libraries

RegFree

Frees memory allocated by RegGetHandle

SYNTAX:

void RegFree(handle)

Home