正規表現はC#, Python, JavaScriptなどでもお世話になっているのである程度自信があります。C++で正規表現を使用してみましたが、少し複雑なのを書くとうまくいかなかったので、ご教示を頂きたく。宜しくお願いいたします。
ツールチェーン:gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9)
ビルドコマンド:g++ hoge.cpp -std=c++14
C++
1using namespace std; 2 3#include <regex> 4#include <iostream> 5 6int main() { 7 regex rg1("^[0-9]+$"); 8 regex rg2("^[\-0-9]+$"); 9 regex rg3("^[\(\-0-9]+$"); 10 smatch m; 11 string str1("123"); 12 string str2("1-2"); 13 cout << regex_match(str1, m, rg1) << endl; 14 cout << regex_match(str1, m, rg2) << endl; 15 cout << regex_match(str1, m, rg3) << endl; 16 cout << regex_match(str2, m, rg1) << endl; 17 cout << regex_match(str2, m, rg2) << endl; 18 cout << regex_match(str2, m, rg3) << endl; 19 return 0; 20}
期待する結果
text
11 21 31 40 51 61
実行結果
text
11 21 30 40 51 60
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/12 09:19
2018/03/12 09:22
2018/03/12 09:29