glibc regular expression

Discussion in 'C Programming' started by Jonas, Jul 14, 2003.

  1. Jonas

    Jonas Guest

    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)$$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)$$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)$$85899345920$|
    string is matching reg exp
    nick: [Sunet]smurf
    desc: hmm
    connection: LAN(T3)
    mail:
    start: 6 stop: 70
    Jonas, Jul 14, 2003
    #1
    1. Advertising

  2. Jonas

    Jack Klein Guest

    On Mon, 14 Jul 2003 23:10:50 +0200, "Jonas"
    <> 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)$$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
    Jack Klein, Jul 15, 2003
    #2
    1. Advertising

  3. Jonas

    Jonas Guest

    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" <> wrote in message
    news:...
    > On Mon, 14 Jul 2003 23:10:50 +0200, "Jonas"
    > <> 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)$$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
    Jonas, Jul 15, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    2
    Views:
    2,287
  2. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    845
    Alan Moore
    Dec 2, 2005
  3. GIMME
    Replies:
    3
    Views:
    11,948
    vforvikash
    Dec 29, 2008
  4. =?UTF-8?B?0LTQsNC80ZjQsNC9INCzLg==?=

    access to glibc-2.3 threaded locale API

    =?UTF-8?B?0LTQsNC80ZjQsNC9INCzLg==?=, Sep 1, 2003, in forum: Python
    Replies:
    1
    Views:
    323
    Martin v. =?iso-8859-15?q?L=F6wis?=
    Sep 1, 2003
  5. Grant Edwards

    glibc detected double free or corruption

    Grant Edwards, Dec 20, 2006, in forum: Python
    Replies:
    0
    Views:
    421
    Grant Edwards
    Dec 20, 2006
Loading...

Share This Page