2016-11-08 1 views
8

私は、データストリーム内の興味深いデータならば、いくつかのチャンクに一致するようにしようとしています。なぜregex 'を昇格しないのですか。{2}'は '??'

あり(非shecksumが指定されていない場合又は??)主要<次いで4つの英数字、チェックサムの2つの文字であると末尾>べきです。最後の2つの文字が英数字の場合は、予想通り

は、次のコードは動作します。彼らは??だが失敗する。

// Set up a pre-populated data buffer as an example 
std::string haystack = "Fli<data??>bble"; 

// Set up the regex 
static const boost::regex e("<\\w{4}.{2}>"); 
std::string::const_iterator start, end; 
start = haystack.begin(); 
end = haystack.end(); 
boost::match_flag_type flags = boost::match_default; 

// Try and find something of interest in the buffer 
boost::match_results<std::string::const_iterator> what; 
bool succeeded = regex_search(start, end, what, e, flags); // <-- returns false 

私は、こうである必要があります示唆してthe documentationで何かを発見していませんでした(NULLと改行すべてが、マッチAIUIでなければなりません)。

だから私は何を見逃していますか?

+1

から削除されますか?鉱山(gcc)は、 "trigraph ??>が}に変換された"という明示的な警告を出します。 – SingerOfTheFall

+0

私は2008年のツールチェーンを使用してVisual Studio 2013を使用しています。 –

答えて

10

??>trigraphあるので、あなたのコードは同等です、}に変換されます。

// Set up a pre-populated data buffer as an example 
std::string haystack = "Fli<data}bble"; 

// Set up the regex 
static const boost::regex e("<\\w{4}.{2}>"); 
std::string::const_iterator start, end; 
start = haystack.begin(); 
end = haystack.end(); 
boost::match_flag_type flags = boost::match_default; 

// Try and find something of interest in the buffer 
boost::match_results<std::string::const_iterator> what; 
bool succeeded = regex_search(start, end, what, e, flags); // <-- returns false 

あなたがこれに変更することができます。

std::string haystack = "Fli<data?" "?>bble"; 

Demo(注意:私はstd::regexを使用これは多かれ少なかれ同じである)

注:トライグラフは、C++ 11から廃止されて、(おそらく)を使用しているどのようなコンパイラC++ 17

+0

あなたはそれを持っています。非常に興味深い - 私は前に三方グラフのことを聞いていないだろう! –

+0

彼らが削除(または廃止予定?)しまった最新の規格にC++ 11から非推奨 – sehe

+1

@seheは、C++ 17で削除されます – Danh

関連する問題