MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 2 | #include <regexp.h> |
| 3 | |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 4 | string * regexp(string *list, string pattern) |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 5 | string * regexp(string *list, string pattern, int opt) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 6 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 7 | DESCRIPTION |
| 8 | Match the pattern <pattern> (interpreted according to <opt> if |
| 9 | given) against all strings in list, and return a new array with all |
| 10 | strings that matched. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 11 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 12 | If there is an error in the regular expression, a runtime |
| 13 | error will be raised. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 14 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 15 | EXAMPLES |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | string strs; |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 17 | string pattern; |
| 18 | |
| 19 | if (regexp_package() == RE_PCRE) |
| 20 | pattern = "\\<help\\>.*\\<me\\>"; |
| 21 | else |
| 22 | pattern = "\\bhelp\\b.*\\bme\\b"; |
| 23 | |
| 24 | if (strs = regexp(({"please, help me Sir John."}), pattern)) { |
| 25 | if (sizeof(strs) |
| 26 | write("It matches.\n"); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 27 | } |
| 28 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 29 | The regular expression will test the given string (which is |
| 30 | packed into an array) if there is something like "help ... me" |
| 31 | inside of it. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 32 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 33 | HISTORY |
| 34 | LDMud 3.3 added the optional <opt> argument. |
| 35 | Since 3.5.0 a error is raised if RE_PCRE is specified in <opt>, but |
| 36 | the driver lacks PCRE support. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 37 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame^] | 38 | SEE ALSO |
| 39 | regexplode(E), regmatch(E), regreplace(E), regexp_package(E), sscanf(E), |
| 40 | regexp(C) |