Cold Help System: Programming: ColdC Reference Manual: Functions: String: match_regexp()


LIST match_regexp(STRING str, STRING regexp[, INTEGER cs])

This function matches the regular expression argument regexp against the argument str. If cs is specified and is true, the match is case-sensitive; otherwise, it is case-insensitive. If the match succeeds, match_regexp() returns a ten-element list giving the substitutions for the match (see below); otherwise, match_regexp() returns 0. If the argument regexp is not a valid regular expression, the error ~regexp is thrown.

This function is often used when all that is desired is whether a match was made or not. The function regexp() is better for handling the full results of a regexp match. For more information on ColdC Regular Expressions see the section ColdC Regular Expressions.

The substitutions are the text in str which matches the parenthesized subexpressions in regexp. The first substitution is the text in str which matches the whole regexp. Thus, a regular expression can contain no more than nine parenthesized subexpressions. Substitutions are returned as two-element lists [start, len] giving the index of the matching text in str and the length of the text.

Examples:

match_regexp("fooBAR", "bar")
=> [[4, 3], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
match_regexp("Greg says, 'Hello.'", "^([^ ]+) says, '(.*)'$")
=> [[1, 19], [1, 4], [13, 6], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
match_regexp(" 300 100 200 ", "[0-9]+")
=> [[2, 3], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0], [0, 0]]
match_regexp("foo", "bar")
=> 0
match_regexp("Foo", "foo", 1)
=> 0


crypt() | explode() | lowercase() | match_begin() | match_pattern() | match_regexp() | match_template() | pad() | regexp() | strcmp() | strfmt() | strgraft() | strlen() | strsed() | strsub() | substr() | uppercase() | match_crypted() | split() | stridx()


the Cold Dark