Regex infinite loop

hi guys,

surprisingly this is the first time ever using regular expressions,I have heard about them but never delved into them up until this point.

So I am messing around with regex and I seem to be stuck in an infinite loop,

could anyone tell me why this is happening and how I can break out of the loop once I have gathered all the email addresses?

thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include <iostream>
#include <regex>
#include <vector>

using namespace std;

int main()
{
   string input;
   regex reg("[[:digit:]]-[[:digit:]]-[[:digit:]]");
   regex e("abc[drg]*");
   regex email("[[:w:]]+@[[:w:]]+\\.com");
   //regex gmail("[[:w:]]+@gmail\\.com");
   smatch matches;
   vector<string> found;

   cin >> input;
   while(regex_search(input,matches,email)){

   cout << "enter an email" << endl;

   cout << "match!!!" << endl;
   found.push_back(matches.str());

    cout << matches.size() << endl;

    email = matches.suffix().str();
   }
}
What's your input?
adam@gmail.com
It loops because you don't ask for new input.
Topic archived. No new replies allowed.