Closed mlepinay closed 7 years ago
Hm, my guess is that this is an issue with the regex itself. It looks like you have a number of nested capture groups (i.e. everything within parens). Maybe try a different regex for just matching the URL or try using non-capturing matching groups: (?:...)
.
Your replacement function should be run for every match found in the regex, and since you match multiple nested strings of the top-level string the behavior you are seeing seems expected.
Try our regex out on https://regex101.com/ and see what you find.
I am in the end using a much simpler regex for the match. Then I am doing:
if (!LINK_DETECTION_REGEX.test(match)) {
return '';
}
Which I am not super happy about. But it does the job for now.
OK, feel free to reopen if you have issues
I am trying to use your library this way to detect URLs in a string and reformat with some react components:
The problem I have is that this regex makes the callback trigger 3 times with a standard URL such as:
http://i.imgur.com/Pw4Xk7H.gif
First time withmatch === "http://i.imgur.com/Pw4Xk7H.gif"
(which is what I want) But then withmatch === "i.imgur.com"
And again withmatch === "com"
After that it just crashes with the error:
Is it a bug? Is my regex wrong? (it was working with javascript replace)
Can someone investigate on this? Thanks