Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost.Regex: Iterate over named captures/groups
From: Anthony Foiani (tkil_at_[hidden])
Date: 2012-01-31 11:49:19

NoRulez <norulez_at_[hidden]> writes:

> if I have a regex (e.g.: "^Subject: (Re: |Fw: )*(?<subject>.*)")
> I know I can access them with what["subject"] but is there a way to get
> a list or whatever of named captures/groups?

What would you expect to see?

You asked for a named group "subject", which matches zero or more
characters; as such, it will *always* match (if the whole match
succeeds) but it might be empty.

And as for "(Re: |Fw: )*", it will always be submatch 1, and its
contents will most likely be whatever it found on the last time

You do have one good question here: I don't know how Boost.Regex would
signal that "(Re: |Fw: )*" didn't match at all. (Perl would use undef
to distinguish between that case and the empty string, but C++ doesn't
have that option.)

And it looks like the answer is (surprise!) in the documentation
   (or: )

Hope this helps,

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at