iansinnott / iansinnott/react-string-replace

Encountered undefined value during string replacement and weird behaviour

Aberta
#90 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
JavaScript
Estrelas
666
Forks
54
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Direção de pesquisa

Comece com a chamada de reactStringReplace e a expressão regular fornecidas, reproduzindo a saída com a string de exemplo. Rastreie como os grupos de captura são passados para a função de substituição; está concluído quando cada token `{form x}` e `{form x:y}` é substituído uma vez com os dados de correspondência esperados.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
javascript, react
Domínio
frontend
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
35/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.