?
Solved

Help with regex_search (boost regex++)

Posted on 2003-03-11
10
Medium Priority
?
1,875 Views
Last Modified: 2013-12-14
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 =???
}
0
Comment
Question by:apatia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 2
10 Comments
 
LVL 8

Expert Comment

by:Exceter
ID: 8123593
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
 

Author Comment

by:apatia
ID: 8123728
"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
 

Author Comment

by:apatia
ID: 8123757
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:Exceter
ID: 8124397
>> 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
 

Author Comment

by:apatia
ID: 8128147
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
 

Author Comment

by:apatia
ID: 8130768
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
 

Expert Comment

by:SpideyMod
ID: 8130935
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
 
LVL 8

Expert Comment

by:Exceter
ID: 8136881
No objection here.
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8137030
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
 
LVL 8

Expert Comment

by:Exceter
ID: 8137070
You are most welcome.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses
Course of the Month12 days, 4 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question