blob: b29588cb1777b7c8bdfadc1693931c82a6ba3d44 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001SYNOPSIS
2 #include <regexp.h>
3
Zesstra715ec202025-07-09 22:18:31 +02004 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)
MG Mud User88f12472016-06-24 23:31:02 +02009
10DESCRIPTION
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
Zesstra715ec202025-07-09 22:18:31 +020033
34EXAMPLES
MG Mud User88f12472016-06-24 23:31:02 +020035 regmatch("abcdefcdf", "cd") -> "cd"
36 regmatch("abcdefcdf", "cd(e)") -> "cde"
37
38 regmatch("abcdefcdf", "cd", RE_MATCH_SUBS) -> ({ "cd" })
39 regmatch("abcdefcdf", "cd(e)", RE_MATCH_SUBS) -> ({ "cde", "e" })
40
41HISTORY
42 Introduced in LDMud 3.3.198.
43 Modified in 3.3.214 to return 0 for non-matches, and to take and
44 return a start position.
Zesstra715ec202025-07-09 22:18:31 +020045 Since 3.5.0 a error is raised if RE_PCRE is specified in <opt>, but
46 the driver lacks PCRE support.
MG Mud User88f12472016-06-24 23:31:02 +020047
48SEE ALSO
49 regexplode(E), regreplace(E), regexp(E), regexp_package(E), regexp(C)