AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [solved] regex (https://forums.alliedmods.net/showthread.php?t=143154)

Lightokun 11-15-2010 06:21

[solved] regex
 
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


Lightokun 11-15-2010 07:28

Re: [help] regex
 
Solved with other functions.


All times are GMT -4. The time now is 11:23.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.