step() — Pattern match with regular expression

Standards

Standards / Extensions C or C++ Dependencies

XPG4
XPG4.2

both  

Format

#define _XOPEN_SOURCE
#include <regexp.h>

int step(const char *string, const char *expbuf);

extern char *loc1, *loc2;

General description

Restriction: This function is not supported in AMODE 64.

The step() function attempts to match an input string of characters with the compiled regular expression which was obtained by an earlier call to compile().

The first parameter string is a pointer to a string of characters to be checked for a match.

expbuf is the pointer to the regular expression which was previously obtained by a call to compile().

Usage notes

  1. The external variables cirf, sed, and nbra are reserved.
  2. The application must provide the proper serialization for the compile(), step(), and advance() functions if they are run under a multithreaded environment.
  3. The compile(), step() and advance() functions are provided for historical reasons. These functions were part of the Legacy Feature in Single UNIX Specification, Version 2. They have been withdrawn and are not supported as part of Single UNIX Specification, Version 3. New applications should use the newer functions fnmatch(), glob(), regcomp(), and regexec(), which provide full internationalized regular expression functionality compatible with ISO POSIX.2 standard.

Returned value

If some substring of string matches the regular expression in expbuf, step() returns nonzero.

If there is no match, step() returns 0.

If there is a match, step() sets two external pointers, as follows:
  • The variable loc1 points to the first character that matched the regular expression.
  • The variable loc2 points to the character after the last character that matched the regular expression.
For example, if the regular expression matches the entire input loc1 will point to the first character of string and loc2 will point to the NULL at the end of string.

Related information