Veteran Member
Join Date: Feb 2007
Location: Tennessee
|
06-18-2012
, 10:22
Re: [TUT] Regular Expressions
|
#13
|
Try this include.
Spoiler
Code:
/**
* Compiles a regex pattern to work with regex_split_c()
* Does not work properly with regex_match_c()
*
* @param pattern - The pattern to compile, which selects the delimiter
* @param ret - Error code if failure
* @param error - Error message if failure
* @param maxLen - Maximum length of the error message
* @param flags - General flags for the regular expression
* i = Ignore case
* m = Multilines (affects ^ and $ so that they match
* the start/end of a line rather than matching the
* start/end of the string).
* s = Single line (affects . so that it matches any character,
* even new line characters).
* x = Pattern extension (ignore whitespace and # comments).
*
* @return -1 on error in the pattern, > valid regex handle (> 0) on success
*
* @note This handle is automatically freed on map change. However, if you are completely
* done with it before then, you should call regex_free on this handle.
*
*/
stock Regex:regex_compile_split(const pattern[], &ret, error[], maxLen, const flags[]="")
/**
* Splits a string using a pattern to select the delimiter
*
* @param string - The string to split
* @param pattern - The pattern that matches the delimiter
* @param ret - Error code on failure, number of matches on success
* @param output - The array holding the pieces that were split
* @param outputSize - The maximum pieces to store in the output
* @param outputLen - The maximum length of a piece to store in the output
* @param error - Error message on failure
* @param maxLen - Maximum length of the error message
* @param flags - General flags for the regular expression
* i = Ignore case
* m = Multilines (affects ^ and $ so that they match
* the start/end of a line rather than matching the
* start/end of the string).
* s = Single line (affects . so that it matches any character,
* even new line characters).
* x = Pattern extension (ignore whitespace and # comments).
*
* @return -2 = Matching error (error code is stored in ret)
* 0 = No match.
* >1 = Number of results.
*
*/
stock regex_split(const string[], const pattern[], &ret, output[][], outputSize, outputLen, error[], maxLen, const flags[] = "")
/**
* Splits a string using a compiled pattern to select the delimiter
*
* @param string - The string to split
* @param pattern - The compiled pattern that matches the delimiter
* @param ret - Error code on failure, number of matches on success
* @param output - The array holding the pieces that were split
* @param outputSize - The maximum pieces to store in the output
* @param outputLen - The maximum length of a piece to store in the output
*
* @return -2 = Matching error (error code is stored in ret)
* 0 = No match.
* >1 = Number of results.
*
*/
stock regex_split_c(const string[], Regex:pattern, &ret, output[][], outputSize, outputLen)
Code:
#include <amxmodx>
#include <regex_split>
public plugin_init() {
new ret, error[128];
new Regex:pattern = regex_compile_split(" ", ret, error, charsmax(error));
new output[10][2];
new count = regex_split_c("1 2 3 4 5 6 7 8 9", pattern, ret, output, sizeof(output), charsmax(output[]));
for(new i = 0; i < count; i++) {
log_amx("Found: %s", output[i]);
}
count = regex_split("a:b:c d:e", " ", ret, output, sizeof(output), charsmax(output[]), error, charsmax(error));
for(new i = 0; i < count; i++) {
log_amx("Found: %s", output[i]);
}
}
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw
I love you exolent!
|
Last edited by Exolent[jNr]; 06-18-2012 at 10:23.
|
|