VC++ (regex.cpp):
#include <iostream>
//#include <string>
#include <regex> //string lib here
using namespace std;
int main(void)
{
int r = 0;
string number = "";
//匹配模型
regex number_format("[0-9]{1,5}");
//隨機數
srand(time(NULL));
r = rand()%10;
cout << "Input number:" << endl;
cin >> number;
//資料比對
if(regex_match(number, number_format)) {
cout << number << " * " << r << " = " << stoi(number) * r << endl;
} else {
cout << "Not match." << endl;
}
system("pause");
return 0;
}
說明:
基本的正規表示法進行數字的匹配,並乘上一隨機數。
沒有留言:
張貼留言