Next: , Previous: , Up: Functions   [Contents][Index]


4.2 Matching Strings

The functions below return match descriptor, i.e. a positive number that can be used to retrieve further information about the match (see Capturing groups). On failure (string doesn’t match the oregular expression), they return 0.

If the supplied match descriptor is not valid, these functions will raise the e_range exception.

Function: number pcre_match (number rx, string subject)

First argument is regex descriptor returned by previous call to pcre_compile.

The function matches subject against the regular expression referred to by rx. Returns match descriptor on success and 0 on failure.

Function: number pcre_string_match (string rs, string subject)

Compiles rs into a regular expression and matches string subject against it. Returns match descriptor on success and 0 on failure.

When no longer used, the match descriptor should be freed:

Function: void pcre_match_free (number mh)

Frees the resources allocated for the match descriptor mh and returns it to the pool for eventual re-use.

The two functions below return a boolean value: true (1) if the string matches and false (0) if it doesn’t.

Function: number pcre_matches (number rx, string subject)

First argument is regex descriptor returned by a previous call to pcre_compile.

Returns true if string matches that regular expression and false otherwise.

Function: number pcre_string_matches (string rs, string subject)

Compiles rs into a regular expression and matches string subject against it. Returns true if the match is found and false otherwise.