Open System Services Library Calls Reference Manual (G06.28+, H06.05+)
regcomp(3) OSS Library Calls Reference Manual
char patt[SLENGTH], strng[SLENGTH];
|
char *eol;
|
(void)setlocale(LC_ALL, "");
|
printf("Enter a regular expression:");
|
fgets(patt, SLENGTH, stdin);
|
if ((eol = strchr(patt, ’\n’)) != NULL)
|
*eol = ’\0’; /* Replace newline with null */
|
else
|
return; /* Line entered too long */
|
printf("Enter string to compare\nString: ");
|
fgets(strng, SLENGTH, stdin);
|
if ((eol = strchr(strng, ’\n’)) != NULL)
|
*eol = ’\0’; /* Replace newline with null */
|
else
|
return; /* Line entered too long */
|
match(patt, strng);
|
}
|
int match(char *pattern, char *string)
|
{
|
char message[SLENGTH];
|
char *start_search;
|
int error, msize, count;
|
regex_t preg;
|
regmatch_t pmatch;
|
error = regcomp(&preg, pattern,
|
REG_ICASE | REG_EXTENDED);
|
if (error) {
|
msize = regerror(error, &preg, message, SLENGTH);
|
printf("%s\n", message);
|
if (msize > SLENGTH)
|
printf("Additional text lost\n");
|
return;
|
} |
error = regexec(&preg, string, 1, &pmatch, 0);
|
if (error == REG_NOMATCH) {
|
printf("No matches in string\n");
|
return;
|
} else if (error != 0) {
|
msize = regerror(error, &preg, message, SLENGTH);
|
printf("%s\n", message);
|
if (msize > SLENGTH)
|
printf("Additional text lost\n");
|
return; |
}; |
count = 1; |
start_search = string + pmatch.rm_eo; |
while (error == 0) { |
error = |
5−94 Hewlett-Packard Company 527187-007