問題タブ [boost-regex]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 正規表現とブースト。単純な正規表現に取り組んでいない
以下は私の次のコードです
常に一致なしで出力します。
正規表現が機能するはずです。
この例を使用しました
http://onlamp.com/pub/a/onlamp/2006/04/06/boostregex.html?page=3
c++ - ブースト正規表現がスタックスペースを使い果たしたのはなぜですか?
これにより、次が生成されます。
でコンパイル
編集
私のプラットフォーム:
c++ - コンパイルされた正規表現 (std::regex) をファイルに保存/シリアル化する方法は?
<regex>
Visal Studio 2010 から使用しています。正規表現オブジェクトを作成するとコンパイルされることを理解しています。他の言語やライブラリのようなコンパイル方法はありませんが、それが機能する方法だと思います。
このコンパイルされた正規表現を大量にファイルに保存する必要があるため、メモリブロックのチャンクを取得してコンパイルされた正規表現を取得するだけです。
これを行う方法がわかりません。PCREでは可能ですが、Linuxライブラリです。Windows [バージョン2がありますが、それは 3 年前のものであり、より高度なアプローチを使用したいと考えています (Windows バージョンには C++ ラッパーはありません)。
save std:regex
or boost::regex
(それは同じ権利ですか?) をメモリのチャンクとして使用し、後でそれを再利用することは可能ですか?
または、これを可能にする Windows 用の他の単純なライブラリはありますか?
編集: 素晴らしい答えをありがとう。単純に正規表現を文字列として保存するだけで十分かどうかを確認し、それでも遅い場合はテストして、この古い PCRE ライブラリと比較します。
c++ - boost::regex_replaceの2つのパラメーター形式関数に関する問題
のフォーマット関数に問題がありますboost::regex_replace
。1つのパラメーターバージョンを呼び出すことはできますが、2つのパラメーターを呼び出すことはできません。
repl_quot
として定義されている場所
上記は機能しますが、その静的変数を実際には使用したくないので、許容できる2つのパラメーターの代替バージョンであると思ったものを試しました。
ただし、regex_replaceはこれを受け入れません(複雑なコンパイラエラー)。Boost::Regex
ドキュメントの以下に基づいて、2つのパラメータバージョンを使用しようとしています。
テンプレートbasic_stringregex_replace(const basic_string&s、const basic_regex&e、Formatter fmt、match_flag_type flags = match_default);
必須タイプフォーマッタは、関数呼び出しから置換文字列を計算する単項、バイナリ、または三項ファンクタのいずれかである必要があります。置換テキストとして使用されるchar_typeのコンテナを返す必要があるfmt(what)、またはfmtのいずれかです。 (what、out)またはfmt(what、out、flags)。どちらも置換テキストを* outに書き込み、新しいOutputIterator位置を返します。いずれの場合も、見つかった一致を表すmatch_resultsオブジェクトは何ですか。
コンパイラエラーメッセージの要求が繰り返されているので、ここにあります(要求する内容に注意してください)。
c:\ boost \ boost \ regex \ v4\regex_format.hppメンバー関数`OutputIterboost :: re_detail :: format_functor_container :: operator()(const Match&、OutputIter、boost :: regex_constants :: match_flag_type、const Traits&)[with OutputIter = boost :: re_detail :: string_out_iterator、std :: allocator >>、Container = const std :: string&(*)(const boost :: smatch&、std :: string&)、Match = boost :: match_results <__ gnu_cxx :: __normal_iterator、std :: allocator >>、std :: allocator、std :: allocator >> >> >>、Traits = boost :: regex_traits_wrapper >>]':
356 c:\ boost \ boost \ regex \ v4 \ match_results.hppは、 `OutputIterator boost :: match_results :: format(OutputIterator、Functor、boost :: regex_constants :: match_flag_type、const RegexT&)const [with OutputIterator = boost :: re_detail :: string_out_iterator、std :: allocator >>、Functor = const std :: string&(*)(const boost :: smatch&、std :: string&)、RegexT = boost :: basic_regex >>、BidiIterator = __gnu_cxx :: __ normal_iterator 、std :: allocator >>、Allocator = std :: allocator、std :: allocator >> >>] '
60 c:\ boost \ boost \ regex \ v4 \ regex_replace.hppは、 `OutputIterator boost :: regex_replace(OutputIterator、BidirectionIterator、BidirectionIterator、const boost :: basic_regex&、Formatter、boost :: regex_constants :: match_flag_type)[with OutputIterator boost :: re_detail :: string_out_iterator、std :: allocator >>、BidirectionIterator = __gnu_cxx :: __ normal_iterator、std :: allocator >>、traits = boost :: regex_traits>、charT = char、Formatter = const std :: string&(* )(const boost :: smatch&、std :: string&)] '
80 c:\ boost \ boost \ regex \ v4 \ regex_replace.hppは、 `std :: basic_string、std :: allocator <_T2>> boost :: regex_replace(const std :: basic_string、std :: allocator<_T2>>からインスタンス化されました&、const boost :: basic_regex&、Formatter、boost :: regex_constants :: match_flag_type)[with traits = boost :: regex_traits>、charT = char、Formatter = const std :: string&(*)(const boost :: smatch&、std ::ストリング&)]'
327 C:\ Dev-Cpp \ Examples \ wordrad\xhtml_open.cppはここからインスタンス化されます
1064 c:\ boost \ boost \ regex \ v4 \ regex_format.hppメンバーのリクエスト
begin' in
((boost :: re_detail :: format_functor_container、std :: allocator >>、std :: allocator、std :: allocator >> >> >>、 boost :: regex_traits_wrapper >>> *)this)-> boost :: re_detail :: format_functor_container、std :: allocator >>、std :: allocator、std :: allocator >> >> >>、boost :: regex_traits_wrapper >> >> :: func'、これは非クラスタイプ `const std :: string&(* const)(const boost :: smatch&、std :: string&)'1064 c:\ boost \ boost \ regex \ v4 \ regex_format.hppメンバーのリクエスト
end' in
((boost :: re_detail :: format_functor_container、std :: allocator >>、std :: allocator、std :: allocator >> >> >>、 boost :: regex_traits_wrapper >>> *)this)-> boost :: re_detail :: format_functor_container、std :: allocator >>、std :: allocator、std :: allocator >> >> >>、boost :: regex_traits_wrapper >> >> :: func'、これは非クラスタイプ `const std :: string&(* const)(const boost :: smatch&、std :: string&)'
c++ - Boost regex_replace 例外: 「...この例外は、「永遠の」一致を防ぐためにスローされます...」がスローされることがある
Boost.Regex(boost-1.42) を使用して、複数行の文字列 ('\n' で終わる複数の行を含むかなり大きな文字列) の最初の行を削除しています。
つまり、regex_replace を使用して s/(.*?) に似た処理を行います\n//
このコードは、次の例外をスローしています。
興味深い/厄介なことに、これは同じテスト データを使用したテスト プログラムでは発生しないようです。なぜこれが起こっているのか、および/またはそれを修正する方法について何か考えはありますか?
c++ - C ++ / Boost:より強力なsscanf置換を作成する
一致をイテレータに割り当てるCのsscanfを置き換える関数をC++で記述したいと思います。
基本的に、私は次のようなものが欲しいです:
正確な詳細は異なる場合がありますが、あなたはその考えを理解します。実装のアイデアはありますか?
これまでのオプションとこれまでの問題:
- std :: istringstream:定数式を照合するためのマニピュレーターはありません
- Boost.Regex:これが機能するかどうかわからないため、これに必要なものよりもはるかに複雑に見える
- Boost.Spirit:これが動的に生成されたフォーマット文字列に対して機能するとは思わない。また、必要以上に複雑に見える
- sscanf:動作しますが、非標準などであり、引数の数はコンパイル時に決定されるため、これを使用すると多くのオーバーヘッドが必要になります。
c++ - 私のC ++正規表現の一致の何が問題になっていますか
C++ で robots.txt パーサーを作成しています
これは * という名前のユーザーエージェントと一致する必要がありますが、すべてのデータを返します
c++ - boost::iostreamsを使用してbashスクリプトをC++に変換する方法
boost::iostreamsを使用して次のbashコードをC++に変換しようとしています。
ファイルを開いて解凍できます。
次に、非圧縮ファイルを開きます。
今、私は少し立ち往生しているので、ここに私の質問があります:
1)2つのストリームを連結するためのboost :: iostreamsソリューションは何ですか?
2)grep / sedをエミュレートするために正規表現フィルターを介して結果を出力するにはどうすればよいですか?
結果として、coutにコピーできるistreamが必要です。
Hamigakiの連結を使用して完全なソリューションを更新します。
c++ - Boost正規表現を使用して文字列からIPアドレスを抽出しますか?
誰かが私を助けてくれるかどうか疑問に思っていました。正規表現の例を探していましたが、それでも頭を悩ませることはできません。
文字列は次のようになります。
「ユーザーJaneDoe、IP:12.34.56.78」
「ユーザーJohnDoe、IP:34.56.78.90」
上記の文字列に一致する式を作成するにはどうすればよいですか?
c++ - BoostRegex C++ による正規表現
こんにちは、次の式の値を取得したいと考えています: POLYGON(100 20, 30 40, 20 10, 21 21) POLYGON(100 20, 30 40, 20 10, 21 21) を検索しています
次のコードを実行すると、次の結果が得られます:
POLYGON(100 20, 30 40, 20 10, 21 21)
結果 = 100 20
r2 = 100
r2 = 20
r2 = , 21 21
r2 = 21
サイズ = 7
なぜ中間値が得られないのかわかりません...
お手伝いありがとうございます