glibc regular expression

J

Jonas

I got a string from which I want to extract some info. The string has a
format like this "$MyINFO $ALL %s %s$ $%s$%s$%s$|" ie "$MyINFO $ALL
[Sunet]smurf hmm$ $LAN(T3)[email protected]$85899345920$|" for doing this I use
the The GNU C Library regular expression library.
My matchstring looks like this "$MyINFO $ALL \\(.*\\) \\(.*\\)$
$\\(.*\\)$\\(.*\\)$\\(.*\\)$|" it works fine for the 4 strings but it's
unable to match the last one which it seems to think starts from the first
space and ends at '|'. I'm a little unsure how the escapes characters works
but I think I got them right, the manual doesnt say much about them (
http://www.gnu.org/manual/glibc-2.2.5/html_mono/libc.html#Regular Expressi
ons ).

thx for your help

/*recives a like $MyINFO $ALL [Sunet]smurf hmm$
$LAN(T3)[email protected]$85899345920$|*/
void process_myinfo( char* cmd ){
regex_t comp_reg;
regmatch_t match[7];
char* sp;
int n;

printf("got: %s\n", cmd);
n = regcomp( &comp_reg, "$MyINFO $ALL \\(.*\\) \\(.*\\)$
$\\(.*\\)$\\(.*\\)$\\(.*\\)$|", 0 );

if( n!=0 ){
printf( "regcomp failed:\n" );
regfree( &comp_reg );
return;
}

n = regexec( &comp_reg, cmd, 5, match, 0 );

if( n==0 ){
printf( "string is matching reg exp\n");

sp = substring( cmd, match[1].rm_so, match[1].rm_eo );
if( sp!=NULL ){
printf("nick: %s\n", sp);
}
free(sp);

sp = substring( cmd, match[2].rm_so, match[2].rm_eo );
if( sp!=NULL ){
printf("desc: %s\n", sp);
}
free(sp);

sp = substring( cmd, match[3].rm_so, match[3].rm_eo );
if( sp!=NULL ){
printf("connection: %s\n", sp);
}
free(sp);

sp = substring( cmd, match[4].rm_so, match[4].rm_eo );
if( sp!=NULL ){
printf("mail: %s\n", sp);
}
free(sp);

printf("start: %d stop: %d\n", match[5].rm_so, match[5].rm_eo);
sp = substring( cmd, match[5].rm_so, match[5].rm_eo );
if( sp!=NULL ){
printf("share: %s\n", sp);
}
free(sp);
fflush(stdout);
}
else{
printf("no match\n");
}
regfree( &comp_reg );
}

outputs:

got: $MyINFO $ALL [Sunet]smurf hmm$ $LAN(T3)[email protected]$85899345920$|
string is matching reg exp
nick: [Sunet]smurf
desc: hmm
connection: LAN(T3)
mail: (e-mail address removed)
start: 6 stop: 70
 
J

Jack Klein

I got a string from which I want to extract some info. The string has a
format like this "$MyINFO $ALL %s %s$ $%s$%s$%s$|" ie "$MyINFO $ALL
[Sunet]smurf hmm$ $LAN(T3)[email protected]$85899345920$|" for doing this I use
the The GNU C Library regular expression library.

This group discusses the standard C language and its library, not
third party libraries from any source. Gnu's regular expression
library is not part of standard C.

Try a group like
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 
J

Jonas

ok sorry then found a question about it in the comp.lang.c faq (
http://www.eskimo.com/~scs/C-faq/q13.7.html ) so i thought it was ok...

Jack Klein said:
I got a string from which I want to extract some info. The string has a
format like this "$MyINFO $ALL %s %s$ $%s$%s$%s$|" ie "$MyINFO $ALL
[Sunet]smurf hmm$ $LAN(T3)[email protected]$85899345920$|" for doing this I use
the The GNU C Library regular expression library.

This group discusses the standard C language and its library, not
third party libraries from any source. Gnu's regular expression
library is not part of standard C.

Try a group like
--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top