Hi everyone. I need help with regex module.
I have a string like this:
Code:
"key1":"value1":some_value|"key2":"value2":some_value|...etc
I need to store keys and values in array, how do i match all key-values?
I have a regex and code:
Code:
#define SETTINGS_PATTERN "^"(.*)^":^"(.*)^":(.*)"
public parse_cfg(id,settings[]) {
new num, error[128], Regex:re
re = regex_match(settings, SETTINGS_PATTERN, num, error, 127)
log_amx("Result=%d, num=%d, error=%s", re, num, error)
if (re >= REGEX_OK)
{
new str2[512], i
for (i=0; i<num; i++)
{
regex_substr(re, i, str2, 511)
log_amx("Substring %d: %s", i, str2)
}
regex_free(re)
}
}
But it returns this:
Code:
L 11/15/2010 - 14:13:24: [eadmin.amxx] Result=1, num=4, error=
L 11/15/2010 - 14:13:24: [eadmin.amxx] Substring 0: "language":"ru":*|"zp_nvg_custom":"on":200|"zp_nvg_color":"255 255 0":200|"zp_fllght_custom":"on":200|"zp_fllght_color":"255 255 0":200|"wariii_class":"6":202|"kz_hat":"0":204|"kz_hp":"10000":204|"kz_weapon":"8":204
L 11/15/2010 - 14:13:24: [eadmin.amxx] Substring 1: language":"ru":*|"zp_nvg_custom":"on":200|"zp_nvg_color":"255 255 0":200|"zp_fllght_custom":"on":200|"zp_fllght_color":"255 255 0":200|"wariii_class":"6":202|"kz_hat":"0":204|"kz_hp":"10000":204|"kz_weapon
L 11/15/2010 - 14:13:24: [eadmin.amxx] Substring 2: 8
L 11/15/2010 - 14:13:24: [eadmin.amxx] Substring 3: 204
When i expects something like this:
Code:
Substring n: language ru *
Substring n: zp_nvg_custom on 200
__________________