simple failure of boost::regex

A

Alan Patterson

I have installed boost 1.33.1 and everything compiled and installed
fine on Windows using Visual C++ 8.0.

I wrote the following simple code to test the regex library and it
doesn't seem to work. In the following "Matched" is not output to
cout.

Am I missing something or do I have a problem with my regex install?

#include <string>
#include <boost/regex.hpp>

using namespace boost;
using namespace std;

int main()
{
string s("hello world");
regex e("hello");

cout << "Testing regex match" << endl;
if (regex_match(s, e)) {
cout << "Matched" << endl;
}

return 0;
}
 
P

Pierre Senellart

"Alan Patterson" ,comp.lang.c++:
int main()
{
string s("hello world");
regex e("hello");

cout << "Testing regex match" << endl;
if (regex_match(s, e)) {
cout << "Matched" << endl;
}

return 0;
}

regex_match only returns true for regexps matching the entire string;
you're looking for regex_search.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top