Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > glibc regular expression

Reply
Thread Tools

glibc regular expression

 
 
Jonas
Guest
Posts: n/a
 
      07-14-2003
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)$(E-Mail Removed)$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....lar%20Expressi
ons ).

thx for your help

/*recives a like $MyINFO $ALL [Sunet]smurf hmm$
$LAN(T3)$(E-Mail Removed)$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)$(E-Mail Removed)$85899345920$|
string is matching reg exp
nick: [Sunet]smurf
desc: hmm
connection: LAN(T3)
mail: http://www.velocityreviews.com/forums/(E-Mail Removed)
start: 6 stop: 70


 
Reply With Quote
 
 
 
 
Jack Klein
Guest
Posts: n/a
 
      07-15-2003
On Mon, 14 Jul 2003 23:10:50 +0200, "Jonas"
<(E-Mail Removed)> wrote in comp.lang.c:

> 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)$(E-Mail Removed)$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 news:gnu.gcc.help.

--
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
 
Reply With Quote
 
 
 
 
Jonas
Guest
Posts: n/a
 
      07-15-2003
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Mon, 14 Jul 2003 23:10:50 +0200, "Jonas"
> <(E-Mail Removed)> wrote in comp.lang.c:
>
> > 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)$(E-Mail Removed)$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 news:gnu.gcc.help.
>
> --
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments