2011-08-08 14 views
0

したがって、一致があるかどうかを調べるために、reg exワイルドカード値のリストに対して文字列(url)をチェックする必要があります。私はHTTPリクエストを傍受し、あらかじめ設定された値のリストと照合し、一致するものがあればURLに何かをします。例:文字列とregExワイルドカード値の比較

これを行うためのC++のライブラリはありますか?どんな良い例も素晴らしいでしょう。私が持っている擬似コードは次のようなものです:

std::string requestUrl = "http://www.stackoverflow.com"; 
std::vector<string> urlWildcards = ...; 

BOOST_FOREACH(string wildcard, urlWildcards) { 
    if (requestUrl matches wildcard) { 
     // Do something 
    } else { 
     // Do nothing 
    } 
} 

ありがとう。

+1

この投稿を見てください。 http://stackoverflow.com/questions/4716098/regular-expressions-in-c-stl – BrandonSun

答えて

0

次のコード例では、正確な部分文字列の一致を探すために正規表現を使用しています。検索は、2つの文字列を入力として使用する静的IsMatchメソッドによって実行されます。最初は検索対象の文字列、2番目は検索対象の文字列です。 MSDNから

#using <System.dll> 

using namespace System; 
using namespace System::Text::RegularExpressions; 

int main() 
{ 
    array<String^>^ sentence = 
     { 
      "cow over the moon", 
      "Betsy the Cow", 
      "cowering in the corner", 
      "no match here" 
     }; 

    String^ matchStr = "cow"; 
    for (int i=0; i<sentence->Length; i++) 
    { 
     Console::Write("{0,24}", sentence[i]); 
     if (Regex::IsMatch(sentence[i], matchStr, 
       RegexOptions::IgnoreCase)) 
      Console::WriteLine(" (match for '{0}' found)", matchStr); 
     else 
      Console::WriteLine(""); 
     } 
     return 0; 
    } 
} 

コード(http://msdn.microsoft.com/en-us/library/zcwwszd7(v=vs.80).aspx)。

+0

これはC++/CLR用です。質問は、ネイティブのC + +のソリューションを求めるようだ。 – Xion