[pcre-dev] split string using pcre in c

Pàgina inicial
Delete this message
Autor: Brad Lira
Data:  
A: pcre-dev
Assumpte: [pcre-dev] split string using pcre in c
Hello,

I would like to split a string into tokens using pcre in c/c++, the
documentation talks alot about matching a string,
but not so much tokenizing, basically i want to be able to do the
following shown in perl but in c/c++.

-----------------
use strict;
use warnings;
my $str = 'command1 [hello my dear] command2 command3 "command4
--some-arg arg --some- +other-arg 2" command5 command6';

for (split m{(\s+|"[^"]*"|\[[^\[]*\])}, $str) {
            print $_, $/;
    }


output:
-----------
command1
[hello my dear]
command2
command3
"command4 --some-arg arg --some- +other-arg 2"
command5
command6

thanks,
brad.