Help with regex_search (boost regex++)

I need help using the boost regex++ regex_search function. I'm trying to search a string for a particular pattern and then save the matching sub-expression (should be what[1]) to match_str. However, I can't seem to retrieve it. "match_str" (and str3)  is always null. I've tried the following:
   match_str = what[1];
   match_str = what[1].first;
   std::string str3(what[1].first, what[1].second);
None of them work.
My code compiles. I confirmed that the regular expression is accurate and result== true (meaning a match was found) when I try to set match_str.

I'd appreciate any help you may have.


//Test.cpp
#include <boost/regex.hpp>

void main() {
  bool result =false;
  std::string search_str("Dim variable1 As String  'Stuff Stuff Stuff");
  boost::match_results<std::string::const_iterator>  what;
  boost::regex expression("\\s*.*\\s(\\'.*));  //This looks for comment (VB) at string
  std::string::const_iterator start, end;
  std::string match_str;

  start = search_str.begin();
  end  = search_str.end();

  result = boost::regex_search(start,end,what,expression,boost::match_default);
  if (result)
     match_str =???
}
apatiaAsked:
Who is Participating?
 
SpideyModConnect With a Mentor Commented:
PAQ'd and points refunded.

Exceter, my thanks for you in returning to allow apatia to receive the points back quicker.  A sign of a true professional.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
ExceterCommented:
Here is an example of how to use regex_search,
http://boost.org/libs/regex/example/snippets/regex_search_example.cpp

>> My code compiles.

Odd.

>> boost::regex expression("\\s*.*\\s(\\'.*));

Where is the closing quote mark?

Exceter
0
 
apatiaAuthor Commented:
"Dim variable1 As String  'Stuff Stuff Stuff"

The above string is Visual Basic code. The VB comment marker is a single quote - a "closing quote" isn't necessary.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
apatiaAuthor Commented:
Sorry, I misunderstood your post: That is a typo. That line of code should read
"... expression("\\s*.*\\s(\\'.*)");"

I don't have a problem with compiling. My problem is that I cannot retrieve the portion of the string "Dim variable1 As String  'Stuff Stuff Stuff" that matches the part of the regular expression "expression" that's in parentheses - "(\\'.*)"
0
 
ExceterCommented:
>> I don't have a problem with compiling.

Unless the code you posted above is not your actual source code I fail to see how it would compile while it was missing that quote mark.

Exceter
0
 
apatiaAuthor Commented:
I mis-typed the code that I posted. In the code that I'm compiling and running, the second quote mark is there.  Therefore, there's no compilation problem.
0
 
apatiaAuthor Commented:
I don't know why my code doesn't work, but after hours of staring at the regex++ libraries, I found a different object to use (RegEx vs regex) and a different way to accomplish what I want to do.  I'm having this question closed.
0
 
SpideyModCommented:
A request for refund has been made.  Experts you have 72 hours to object to the request and state why.  I will return in 72 hours and intend to grant the request if there's no further feedback.

SpideyMod
Community Support Moderator @Experts Exchange
0
 
ExceterCommented:
No objection here.
0
 
ExceterCommented:
You are most welcome.
0
All Courses

From novice to tech pro — start learning today.