regex() — Execute compiled regular expression

Standards

Standards / Extensions C or C++ Dependencies
XPG4.2 C only  

Format

#define _XOPEN_SOURCE_EXTENDED  1
#include <libgen.h>

char *regex(const char *cmppat, const char *subject[,subexp,...]);

extern char *__loc1;

General description

Restriction: This function is not supported in AMODE 64.

The regex() function executes a converted pattern cmppat produced by the regcomp() function against a subject string. If cmppat matches all or part of the subject string, the regex() function returns a pointer to the next unmatched character in the subject string and sets the external variable __loc1 to point the first matched character in the subject string. If no match is found between cmppat and the subject string, the regex() function returns a NULL pointer.

The regex() and regcomp() functions are supported in any locale. However, results are unpredictable if they are not run in the same locale.

Refer to regcmp() — Compile regular expression for a description of regular expression syntax and semantics supported by the regex() and regcomp() functions.

Note:

The regcmp() and regex() 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.

If it is necessary to continue using these functions in an application written for Single UNIX Specification, Version 3, define the feature test macro _UNIX03_WITHDRAWN before including any standard system headers. The macro exposes all interfaces and symbols removed in Single UNIX Specification, Version 3.

Returned value

If regex() successfully matches the converted pattern cmppat to all or part of the subject string, it returns a pointer to the next unmatched character in subject.

If unsuccessful, regex() returns a NULL pointer.

Related information