regex for emails also pulls out files?

I have a regex that pulls out emails. It is inserted in a c++ program inside of a system() call (don't ask why), and ran in terminal. The problem is, along with the emails, it also pulls out things like test.exe, program.cpp, blah.txt, and so on. I'm trying to make it where it only pulls out things with a @ character in it.

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <cstdlib>
using namespace std;

int main(){

system("grep -rIhEo \"\\b[a-zA-Z0-9.-]+\\@[a-zA-Z0-9.-]+\\.[a-zA-Z0-9.-]+\\b\" /home/*.txt >> ~/emails.txt");

return 0;
}


Now, I know I could add a sed command and remove all the lines with certain file extensions, but I don't want to. Does anyone see what is wrong here?
Topic archived. No new replies allowed.