I am using regex and am having some weird returns. I can assign my results to a std:vector std:string. The vector[0] does contain the correct match, but vector[1] does not contain what is in a set of parentheses as it should. In fact I usually get a segment fault when I try to access it.
I then found I can access results from the grep by using the boost::Regex.What(n). However What(0) returns the next available match in the string, and What(1) and up will correctly report the substrings defined in this second match correctly. If no second match is available then the What() member will return the original match.
How do I fix the vector problem? OR? Does using What() force another search to take place? And if so can I change that behavior?
You are using class RegEx incorrectly:
RegEx::Grep finds all the matches of the expression in the text given and
for each match pushes $& onto the vector - if there is only one match found
then there will be only one string in the vector (check the return value or
the vectors size to find out how many there are), it does *not* push $1 $2
etc onto the vector. After a call to RegEx::Grep then RegEx::What returns
the last match that was found in the string (with What(1) containing $1 for
the last match found etc).
The following is a rewritten version of your code that actually compiles (!)
and does the right thing:
#include