Show toolbar

2014年7月2日 星期三

Simple Regular expression

標題:基本正規表示法
VC++ (regex.cpp):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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;
}

說明:
基本的正規表示法進行數字的匹配,並乘上一隨機數。

沒有留言:

張貼留言