sregex_token_iterator

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

sregex_token_iterator

Jean-Sebastien Vachon
Hi All,

I have a string in the following form:

w="id = 10" C=field1 G=GeoRaster X=leMHG08wViX2quWNB

All I want is to iterator onto the key/values pairs.

w
"id = 10"
C
field1
G
GeoRaster
X
leMHG08wViX2quWNB

The key/value pairs are separated by spaces. However, I can not
simply use a space pattern to iterate over my input string since the
W option allows the user to use "" to include spaces.

Can someone tell me what is wrong in the following code?
oParametersValue represents my input string.

 regex eParam("(.)=(\"?.*\"?)", regex::normal | regbase::icase);

 int const sub_matches[] = { 1, 2 }; // key, value

 sregex_token_iterator oIter(oParametersValue.begin(),
                            oParametersValue.end(), eParam,
                            sub_matches);

 sregex_token_iterator j;
 while (oIter != j)
 {
    std::cout << *oIter++ << std::endl;
 }

Thanks


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: sregex_token_iterator

John Maddock
> regex eParam("(.)=(\"?.*\"?)", regex::normal | regbase::icase);

The .* is greedy so it gobbles up all remaining input including spaces and
quotes.

How about:

(.)=((?:\"[^\"]*\")|(?:[^[:space:]]*))

John.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: sregex_token_iterator

Jean-Sebastien Vachon
On
Thu, 06 Apr 2006 10:32:05 +0100, John Maddock wrote:

>> regex eParam("(.)=(\"?.*\"?)", regex::normal | regbase::icase);
>
> The .* is greedy so it gobbles up all remaining input including spaces and
> quotes.
>
> How about:
>
> (.)=((?:\"[^\"]*\")|(?:[^[:space:]]*))
>
> John.

Hi,

I just noticed that I posted the wrong regex.
My latest regex was:

(.)=(?(\")[^\"]*|[\\S]*)

I'll give yours a try.

Thanks


_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: sregex_token_iterator

Jean-Sebastien Vachon
In reply to this post by John Maddock
On Thu, 06 Apr 2006 10:32:05 +0100, John Maddock wrote:

>> regex eParam("(.)=(\"?.*\"?)", regex::normal | regbase::icase);
>
> The .* is greedy so it gobbles up all remaining input including spaces and
> quotes.
>
> How about:
>
> (.)=((?:\"[^\"]*\")|(?:[^[:space:]]*))
>
> John.

it works wonderfully

Thanks

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: sregex_token_iterator

John Maddock
In reply to this post by Jean-Sebastien Vachon
> I just noticed that I posted the wrong regex.
> My latest regex was:

:-)

> (.)=(?(\")[^\"]*|[\\S]*)

That shouldn't be a valid regex, a similar alternative would be:

(.)=(?(?=\")\"[^\"]*\"|[\\S]*)

John.
_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users