Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Building regex by vector of others

オープン
#24 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
30/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp

調査の方向性

ベクターベースの foo オーバーロードと (1) のマーク付き正規表現の構築から始め、Boost xpressive 1.65.1 を使って、|=、再代入、コピーされた式の動作を再現します。ベクターのエントリを動的に結合すると capture の分離にどのような影響があるかを確認します。完了条件は、クラッシュや以前の部分式からの capture なしに、マッチしたすべてのエントリが報告されることです。

索引モデルが issue の本文から書いたものです。

説明

Hello.

I need to find which regex of N my string matches.

It's easy to implement if I have them compile time:

sregex re = (s1 = re1)|(s2 = re2)|(s3=re3);
...
std::set<int> foo(const std::string& str) {
 std::set<int> result;
 smatch match;
 if(regex_match(str, match, re)) {
 for(int i = 0; i<3; ++i)
  if(match[i+1]) result.insert(i);
 }
return result;
}

But I have a vector:

std::set<int> foo(const std::string& str, const std::vector<sregex>& reVector) {
 sregex re;
 int index = 1;
 for(auto&& item : reVector) {
   re |= (mark_tag(index++) = item); // (1)
 }

 std::set<int> result;
 smatch match;
 if(regex_match(str, match, re)) {
  for(int i = 0; i<reVector; ++i)
    if(match[i+1]) result.insert(i);
  }
 }
return result;
}

There at (1) |= doesn't work as I expect for some reson, It didn't catch some values.
If I replace it with

 re = re | (mark_tag(index++) = item);

it just crashes. If I replace with:

 auto t = re;
 re = t | (mark_tag(index++) = item);

it making captures of previous tags to be subexpresions matches. So code doesn't work as I want.

Is it any way to prevent sub-expression capture isolation?

As I understand it should be some intermediate type before sregex to express expression under construction. So it will not isolate matches of existing part.

I'm using v1.65.1

主要言語
C++
スター
19
フォーク
40
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

boostorg/xpressive のほかの issue

boostorg/xpressive の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。