Raised This Month: $ Target: $400
 0% 

Regex issue, how to get the both numbers from the line?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kapuzzino
Member
Join Date: Jan 2014
Old 02-02-2014 , 08:30   Regex issue, how to get the both numbers from the line?
Reply With Quote #1

It returns me only the first number, instead of both

PHP Code:
new str[] = "that string contains 55 and 46 numbers"
new pattern[] = "(\d{2})"
new flags[] = "mis"
new num,err[128]
new 
str2
new Regex:re regex_match(str,pattern,num,err,127,flags)
server_print("Result=%d Num=%d Error=%s",re,num,err)

if (
re >= REGEX_OK)
{
    new 
str2[64]
    new 
i
    
   
for (i=0i<numi++)
   {
    
regex_substr(re,i,str2,63)
    
server_print("Substring %d: %s"istr2)
   }
}
          
regex_free(re
results:

Code:
Substring 0: 55
Substring 1: 55

Last edited by Kapuzzino; 02-02-2014 at 08:40.
Kapuzzino is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 02-02-2014 , 11:02   Re: Regex issue, how to get the both numbers from the line?
Reply With Quote #2

regex for amxx is pretty limited, as you can see, it doesn't have a global match flag. you have to use regex_match in a loop to check for more matches, while removing previous match from the string.

you get 55 twice probably cause your pattern is in parentheses
jimaway is offline
Kapuzzino
Member
Join Date: Jan 2014
Old 02-02-2014 , 11:08   Re: Regex issue, how to get the both numbers from the line?
Reply With Quote #3

Quote:
you get 55 twice probably cause your pattern is in parentheses
I think that is must be so, the first match is always must contain whole matches.

any example in a loop for that?

Quote:
regex for amxx is pretty limited
Maybe it depends of other functions in regex lib, like regex_match_c or regex_compile?
Kapuzzino is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 02-02-2014 , 11:21   Re: Regex issue, how to get the both numbers from the line?
Reply With Quote #4

Code:
    new str[] = "that string 44 contains 55 and 46 numbers 88"     new pattern[] = "\d\d"     new flags[] = "mi"     new num,err[128]     new Regex:re     new pos = 0     while (strlen(str[pos]) > 0 && (re = regex_match(str[pos],pattern,num,err,127,flags))>= REGEX_OK )     {         new str2[64]             regex_substr(re,0,str2,63)         server_print("Substring: %s", str2)         pos += contain(str[pos], str2) + strlen(str2)     }               regex_free(re)

Last edited by jimaway; 02-02-2014 at 11:30.
jimaway is offline
Kapuzzino
Member
Join Date: Jan 2014
Old 02-02-2014 , 11:42   Re: Regex issue, how to get the both numbers from the line?
Reply With Quote #5

yes, thats working, I hope I'll found out how to parse whole html page as well.

p.s. if I get it.

Last edited by Kapuzzino; 02-02-2014 at 11:43.
Kapuzzino is offline
Reply



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 17:38.


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