Regular Expressions Searching doesn't work!

I am having trouble using regular expressions. I use Eclipse IDE, gcc compiler, and run Ubuntu. Every time I try to use a regular expression, Eclipse throws up errors. I am trying to search a string for another string, and if that string is present, put it into an array.
What's your code and what are the errors?
Here's my code


#include <iostream>
#include "regex.h"
#include <stdlib.h>
using namespace std;

int main() {

string str="Hello";
string srt2="H";

if(regex_search(str,"H")==true)
{
cout<<"Yay";
}
cout<<"done";

return 0;
}


I was just trying to see how to use regular expressions. It comes up with
'regex_search' was not declared in this scope
using namespace boost;

BTW, I don't know how exactly you are linking, but your code should look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <boost/regex.hpp>
using namespace std;

int main() {
  string tosearch="Hello";
  boost::regex tofindre("H");

  if (boost::regex_search(tosearch,tofindre)) {
    cout<<"Yay";
  }
  cout<<"done";

  return 0;
}
or
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <boost/regex.hpp>
using namespace std;

int main() {
  string tosearch="Hello";
  string tofind="H";

  if (boost::regex_search(tosearch,boost::regex(tofind))) {
    cout<<"Yay";
  }
  cout<<"done";

  return 0;
}

Hope this helps.
Topic archived. No new replies allowed.