Advertisement
giGii

kobezzza regular_1

Apr 1st, 2023
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <regex>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     regex r(R"/(\d{2}\.\d{2}\.(\d{4}|\d{2}))/");
  9.     string s = "20.10.219 Ваша заявка с номером #48278401010101010101 оформлена"s;
  10.     smatch match;
  11.  
  12.     regex_search(s, match, r);
  13.     cout << "match.str() "sv << match.str() << endl; // match.str() 20.10.21
  14.     cout << "match[0].str() "sv << match[0].str() << endl; // match[0].str() 20.10.21
  15.     cout << "match[1].str() "sv << match[1].str() << endl; // match[1].str() 21 <----------вопрос, почему именно 21?
  16. }
  17. ---
  18.  
  19. // почему по шаблону |\d{2} нашлась цифра 21 -- то есть последняя пара цифр, а не первая пара цифр (20) например?
  20.  
  21.  
  22.  
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement