advance() — Pattern match given a compiled regular expression
Standards
Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4
XPG4.2 |
both |
Format
#define _XOPEN_SOURCE
#include <regexp.h>
int advance(const char *string, const char *expbuf);
extern char *loc2, *locs;
General description
The advance() 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().
The external variable loc2 will point to the next character in string after the last character that matched the regular expression.
The external variable locs can be optionally set to point to some point in the input regular expression string to cause the advance() function to exit its back up loop.
- The application must provide the proper serialization for the compile(), step(), and advance() functions if they are run under a multithreaded environment.
- 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 IEEE Std 1003.1-2001.
Returned value
If the initial substring of string matches the regular expression in expbuf, advance() returns nonzero.
If there is no match, advance() returns 0.
If there is a match, advance() sets an external character pointer, loc2, as a side effect. The variable loc2 points to the next character in string after the last character that matched the regular expression.
Related information
- regexp.h — Regular expression declarations
- compile() — Compile regular expression
- fnmatch() — Match file name or path name
- glob() — Generate path names matching a pattern
- regcomp() — Compile regular expression
- regexec() — Execute compiled regular expression
- step() — Pattern match with regular expression