Jump to content

[SOLVED] regexp how to find multi matches?


photo

Recommended Posts

Posted

hi I have a question about the regexp re_search function

i found it only could give the last match result.

example:

string ddd="float A1;float A2;float A3;";
int test[0];
int result=re_search(ddd,".*\bfloat \b(\w+)",test);

it only return the last one "A3" , how should i do to make it return all "A1“ ”A2“ ”A3“?

 

thanks

Posted

Hello,

string ddd="float A1;float A2;float A3;";
int test[0];
int strings[0];
while(re_search(ddd,"\bfloat \b(\w+)",test)) {
   strings.append(test[0]);
   ddd = substr(ddd,strstr(ddd,test[0]));
}
 
forloop(int i = 0; strings.size()) {
   log.message(strings[i] + "\n");
}
×
×
  • Create New...