Игнорирование только букв в регулярных выражениях
У меня есть регулярное выражение:
std::regex rx{ R"((0[1-9]|[12][0-9]|3[01])[.](0[1-9]|1[012])[.](\d\d)\d\d)" };
И есть такой код:
#include <iostream>
#include <string>
#include <vector>
#include <fstream> //для ввода/вывода при работе с файлами
#include <regex>
using namespace std;
string check_filename(string filename)
{
ifstream file;
file.open(filename);
while (!file.is_open())
{
cout << "Input the correct filename>";
getline(cin, filename);
file.open(filename);
}
return filename;
}
string vec_to_str(vector<string> b, string a)
{
a.clear();
for (int i = 0; i < b.size() - 1; ++i)
{
a += b[i] + ' ';
}
a += b[b.size() - 1];
return a;
}
void file_to_str(string& a,string filename)
{
ifstream file;
file.open(filename);
char c;
while ((c = file.get()) != -1)
{
a.push_back(c);
}
}
void ch_to_vec(vector<string>& b, string a)
{
for (int i = 0; i < a.length(); ++i)
{
if (isspace(a[i]) && !b.back().empty())
b.push_back({});
else
b.back() += a[i];
}
}
bool check_wish(bool wish)
{
string no;//переменная,отвечающая за продолжение
do
{
if (no == "y" || no == "yes")
{
wish = true;
}
cout << "Continue? (Y/N)>";
while (!(cin >> no) || (cin.peek() != '\n')) //цикл,отвечающий за проверку вводимых типов данных
{
cin.clear();
while (cin.get() != '\n');
std::cout << "Continue? (Y/N) > ";
}
transform(no.begin(), no.end(), no.begin(), ::tolower); // понимжение регистра
} while (no != "n" && no != "no" && no != "y" && no != "yes");
if (no == "n" || no == "no")
{
wish = false;
}
return wish;
}
void seraching_for_match(vector<string> b, int &count, regex rx, vector<string> date)
{
for (int i = 0; i < b.size(); ++i)
{
if (regex_match(b[i], rx) == true)
{
date.push_back(b[i]);
count = 1;
}
}
}
void seraching_for_min(vector<string> date)
{
string min = date[0];
for (int i = 1; i < date.size(); ++i)
{
if (date[i] < min)
{
min = date[i];
}
}
cout << "Earliest date >" << min << endl;
}
int main()
{
setlocale(LC_CTYPE, "Russian");
//ifstream - файловый ввод ;ofstream - файловый вывод
ifstream file; //объект file класса ifstream - отвечает за входной файл
bool wish = true;
regex rx{ R"((0[1-9]|[12][0-9]|3[01])[.](0[1-9]|1[012])[.](\d\d)\d\d)" };
cout << "Earliest date\n";
while (wish)
{
cout << "Input a filename>";
string filename;
getline(cin, filename);
vector<string> b(1);
string a; //строка a - в нее будет записывать строка из файла,а затем и обновленная строк,если таковая будет
vector <string> date;
file.open(filename);
if (!file.is_open())
{
filename = check_filename(filename);
file.open(filename);
}
if (file.is_open())
{
file_to_str(a, filename);
ch_to_vec(b, a);
int count = 0; //есть ли дата или нет
for (int i = 0; i < b.size(); ++i)
{
/*if (regex_match(b[i], rx) == true)
{
date.push_back(b[i]);
count = 1;
}*/
for (std::sregex_token_iterator ib{ b[i].begin(), b[i].end(), rx }, ie; ib != ie; ++ib)
{
date.push_back(*ib);
count = 1;
std::cout << *ib << std::endl;
}
}
if (count == 1)
{
seraching_for_min(date);
}
if (count == 0)
{
cout << "There are no dates in format \"DD.MM.YYYY\" " << endl;
}
}
file.close();
//file1 << a;
//file1.close();
wish = check_wish(wish);
cin.ignore();
}
return 0;
}
од должен искать в строке выражение типа дд.мм.гггг Как можно настроить код выше,чтобы игнорировались только буквы ?(Например,Текстдд.мм.ггггТекст,или Текстдд.мм.гггг, или дд.мм.ггггТекст, а выводится только дд.мм.гггг) Он это делает, но проблема в том, что если за дд.мм.гггг стоят цифры: 12.12.20023, то он выведет ту часть,которая соответствует шаблону дд.мм.гггг - 12.12.2002, хотя он должен это игнорировать. Как это можно исправить?