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

Encountered undefined value during string replacement and weird behaviour

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, react
領域
frontend

調査の方向性

提供されている reactStringReplace の呼び出しと正規表現から始め、例の文字列で出力を再現します。キャプチャグループが置換関数にどのように渡されるかを追跡します。すべての {form x} および {form x:y} トークンが、期待されるマッチデータで一度ずつ置換されれば完了です。

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

説明

I have this string:
let text = "{form 1} {form 2} {form 1:3}";

and this regexp:
/{form (\d+(:\d+)?)}/g
that should match {form x} and {form x:y}

I am executing:

text = reactStringReplace(text, /{form (\d+(:\d+)?)}/g, (match, i) => { return 'match: ${match}, i: ${i}'; });

then in the return of my component I have this:

    return (
        <div className={"cfs-dove__thread-content-message"}>
            {replacedText &&
                replacedText.map((el, i) => {
                    return (
                        <p key={`lettercontent${i}`} dangerouslySetInnerHTML={{ __html: el }}></p>
                    );
                })}
        </div>
    );

and this is de output:

<div class="cfs-dove__thread-content-message">

  <p>match: 1, i: 1</p>

  <p>2</p>

  <p>match: 1:3, i: 7</p>

  <p>:3</p>

  <p>match: , i: 9</p>

</div>

As you can see, the first and third <p> are fine. But the rest aren`t.
The second is the matched value of {form 2} but didn't enter in the replace function.
The forth is only part of the matched value of {form 1:3} and also didn't enter in the function.
And the last did enters in the replace function but the match is "";

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

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

iansinnott/react-string-replace のほかの issue

iansinnott/react-string-replace の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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