Raised This Month: $ Target: $400
 0% 

[solved] regex


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Lightokun
Member
Join Date: Oct 2009
Old 11-15-2010 , 06:21   [solved] regex
Reply With Quote #1

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
__________________

Last edited by Lightokun; 11-15-2010 at 07:31.
Lightokun is offline
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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