Answer the question
In order to leave comments, you need to log in
How can I convert a string variable to a regular expression?
#include <algorithm>
#include <iostream>
#include <math.h>
#include <fstream>
#include <cstdlib>
#include <vector>
#include <map>
#include <tuple>
#include <set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <cstdio>
#include <regex>
using namespace std;
int main() {
string word, mask;
cin >> word >> mask;
for (size_t i = 0; i < mask.size(); ++i) {
if (mask[i] == '?') {
mask[i] = '.';
}
if (mask[i] == '*') {
mask[i] = '.';
mask.insert(i + 1, "*");
}
}
mask += "$";
regex reg = mask; //Вот здесь ошибка
regex_match(word, reg) ? cout << "YES" : cout << "NO";
system("pause");
}
Answer the question
In order to leave comments, you need to log in
string word, mask;
cin >> word >> mask;
for (size_t i = 0; i < mask.size(); ++i) {
if (mask[i] == '?') {
mask[i] = '.';
}
if (mask[i] == '*') {
mask[i] = '.';
mask.insert(i + 1, "*");
}
}
mask += "$";
char *regular = new char[mask.size()];
for (int i = 0; i < mask.size(); ++i) {
regular[i] = mask[i];
}
regex reg = (regular);
regex_match(word, reg) ? cout << "YES" : cout << "NO";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question