pattern_match()

Purpose

Wild card search for pattern in string

Syntax

int pattern_match(pattern, pat_length, data,
data_length)

Parameters

char *pattern

Pointer to characters for which to search

 

int pat_length

Length of pattern

 

char *data

Data in which to search for the pattern

 

int data_length

Length of the data

Description

The pattern_match() function does a wild card match for the parameter pattern in the parameter data. The matching is done using the following rules:

  • If the pattern length is zero, the match is always successful
  • A '*' character matches any group of characters
  • A '?' character matches any single character
  • Other characters must match exactly (the match is case sensitive)
  • If the pattern is longer than the data and the pattern matches up to the end of the data, the match only succeeds if all the remaining characters in the pattern are ' ' or '*'
  • If the data is longer than the pattern and the pattern matches up to the end of the pattern, the match only succeeds if all the remaining characters in the data are ' '

Return values

Returns TRUE if the pattern matches the data parameter

Example

Here are some example patterns:

"R*" matches data beginning with R (but not r)

"*R" matches data for which the last non-blank character is an R

"?R*" matches data whose second letter is an R

"A*b" matches data beginning with A and ending with b