As in the case of ereg(), this function causes the regular expression stored in pattern to be matched against string, and any references matches are stored in matches. The optional flags parameter can actually contain only the value PREG_OFFSET_CAPTURE. If this parameter is specified, it will cause preg_match() to change the format of matches so that it will contain both the text and the position of each reference inside string. Let's make an example:
As you can see, the $matches array now contains another array for each reference. The latter, in turn, contains both the string matched and its position within $s.
Another function of the PCRE family is preg_match_all, which has the same syntax as preg_match(), but searches a string for all the occurrences of a regular expression, rather than for a specific one. Here's an example: