iansinnott / iansinnott/react-string-replace

Encountered undefined value during string replacement and weird behaviour

未关闭
#90 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
JavaScript
星标
666
派生
54
PR 合并指标
30 天内没有已合并 PR

描述

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 (


{replacedText &&
replacedText.map((el, i) => {
return (


);
})}

);
```

and this is de output:

```

match: 1, i: 1

2

match: 1:3, i: 7

:3

match: , i: 9


```

As you can see, the first and third `

` 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 "";

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。