iansinnott / iansinnott/react-string-replace

Multiple replacements in a string are not working properly

Open
#48 2 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
666
Forks
54
PR merge metrics
No merged PRs in 30d

Description

I am using react-string-replace for translations. I have a string and I want to replace a couple of substitutes.
The code looks like this:
```
ReactStringReplace(
'[link]This is my link[/link] available everywhere or [shortcode].',
/(\[link\].*\[\/link\])|(\[shortcode\])/g,
(match) => {
console.log('match', match);
}
)
```
From my understanding, my regular expression should match only the first link and the `[shortcode]`. But the result in the console looks like this:
```
match [link]This is my link[/link]
match available everywhere or
match [shortcode]
```
I don't understand why is the middle match there. It doesn't match the regular expression.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the ReactStringReplace call and the regular-expression example in the issue, then reproduce the logged matches using the provided string. Trace how the replacement callback is invoked and determine why the intervening text is reported; done means the reported matches and replacement behavior align with the issue's stated expectation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.