I'm trying to edit an open source C++ program to make a simple adjustment so that one of the input's accepts a regexp string instead of a string. I'm a complete C++ noob (never written anything) so I'm hoping someone can point me to a function that will work. Take the following code:
#include <iostream>
#include <string>
int main() {
std::string str1("ABCDEABCABD");
std::string pattern("A");
int count1 = 0;
size_t p1 = str1.find(pattern, 0);
while(p1 != std::string::npos)
{
p1 = str1.find(pattern,p1+pattern.size());
count1 += 1;
}
std::cout << count1 << std::endl;
}
I would like 'pattern' to accept a regular expression of several patterns seperated by the pipe sign, eg 'A|D' (which would output 5 in this case).
From what I gather from this C++ reference page, you cannot supply a regular expression like this to the string::find function. What function can I put here instead?