出典: フリー百科事典『ウィキペディア(Wikipedia)』 (2022/02/15 16:52 UTC 版)
「Boost C++ライブラリ」の記事における「正規表現の利用」の解説
Boost.Regex - 正規表現を利用するライブラリ。フィルタ・検索・パース・テキスト処理に必要な各種関数を持っている。 正規表現の種類としてPCRE、POSIX基本正規表現とPOSIX拡張正規表現が利用可能である。 テキストをパースするプログラムの例。 #include #include #include // Example program parsing the URLint main(int argc, char** argv){ // Check the number of parameters if (argc < 2) return 0; // container for the values std::vector values; // Expression to parse boost::regex expression(// proto host port "^(\?:([^:/\?#]+)://)\?(\\w+[^/\?#:]*)(\?::(\\d+))\?"// path file parameters "(/\?(\?:[^\?#/]*/)*)\?([^\?#]*)\?(\\\?(.*))\?" ); // The formation of the source string to parse (taken from command-line) std::string src(argv[1]); // Parse and filling the container if (boost::regex_split(std::back_inserter(values), src, expression)) { // Output the result const char* names[] = {"Protocol", "Host", "Port", "Path", "File", "Parameters", NULL}; for (int i = 0; names[i]; i++) printf("%s: %s\n", names[i], values[i].c_str()); } return 0;} 詳細は Boost.Regex を参照。 Boost.RegexのサブセットがC++11の標準ライブラリとして取り込まれた。
※この「正規表現の利用」の解説は、「Boost C++ライブラリ」の解説の一部です。
「正規表現の利用」を含む「Boost C++ライブラリ」の記事については、「Boost C++ライブラリ」の概要を参照ください。