MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame^] | 1 | SYNOPSIS |
| 2 | #include <regexp.h> |
| 3 | |
| 4 | string regmatch (string text, string pattern) |
| 5 | string regmatch (string text, string pattern, int opt) |
| 6 | string regmatch (string text, string pattern, int opt, int start) |
| 7 | string *regmatch (string text, string pattern, int opt) |
| 8 | string *regmatch (string text, string pattern, int opt, int start) |
| 9 | |
| 10 | DESCRIPTION |
| 11 | Match the string <txt> against <pattern> (interpreted according |
| 12 | to <opt> if given). If <start> is given, it is the start |
| 13 | position for the match and must be in the range [0..strlen(text)]. |
| 14 | |
| 15 | If there is no match, the result is 0. If there is a match, the exact |
| 16 | result is determined by the flag RE_MATCH_SUBS: |
| 17 | |
| 18 | If the flag RE_MATCH_SUBS is not set, the result is the matched |
| 19 | expression. |
| 20 | |
| 21 | If the flag RE_MATCH_SUBS is set, the result is an array of the |
| 22 | matched string(s) of the first match. Entry [0] is the full string |
| 23 | matching the <pattern>, following entries are the string segments |
| 24 | matching parenthesized subexpressions in <pattern>. If a particular |
| 25 | subexpression didn't have a match, the corresponding array entry will |
| 26 | be 0. |
| 27 | |
| 28 | The last entry in the array will be the new start index in case you |
| 29 | want to repeat the match on the remaining parts of the string. This |
| 30 | new index is usually equal the length of the match, but at least one |
| 31 | higher than the original start index. |
| 32 | |
| 33 | EXAMPLE |
| 34 | regmatch("abcdefcdf", "cd") -> "cd" |
| 35 | regmatch("abcdefcdf", "cd(e)") -> "cde" |
| 36 | |
| 37 | regmatch("abcdefcdf", "cd", RE_MATCH_SUBS) -> ({ "cd" }) |
| 38 | regmatch("abcdefcdf", "cd(e)", RE_MATCH_SUBS) -> ({ "cde", "e" }) |
| 39 | |
| 40 | HISTORY |
| 41 | Introduced in LDMud 3.3.198. |
| 42 | Modified in 3.3.214 to return 0 for non-matches, and to take and |
| 43 | return a start position. |
| 44 | |
| 45 | SEE ALSO |
| 46 | regexplode(E), regreplace(E), regexp(E), regexp_package(E), regexp(C) |