I'm struggling with this C++ compiler error to get my regex_match() function to work. The code:
#include <iostream>
#include <string>
#include <regex>
using namespace std;
struct Person {
Person(string name, int age)
: n{name}, a{age}
{
regex r("^([!:*&%#@^\\[\\]\"\'])+"); // :*[]"'&^%#@!
for(char test : n) {
cout << "Character: " << test;
if(regex_match(test, r)) {
cout << endl << "Error: wrong character!" << endl;
}
}
}
string n;
int a;
};
int main() {
Person Goofy("Goofy",11);
return 0;
}
I want to check if n contains at least one of the characters I wrote in the regex r().
Btw, for people learning regex I've found the great website: https://regex101.com.
Any sugestions? Thx!!