i'm using a regex pattern that based on a dynamic index the current occurence gets matched line per line. However, when the text start to be too long the pattern gets a time out (instead in javascript after a bit the regex engine crush it). I've
tried to improve this solution in this way:
(?<=(?:\btest\b(.|\n)*){index})(?<!(?:\btest\b(.|\n)*){index+1})\btest\b
(here the original pattern solution demo)
might be possible to be related with the backtracking problem?
ps. index in regex pattern is dynamic because is applied in js context.
It seems the react-highlight-regex package does not have any way to indicate the part to highlight in any other way.
To avoid the enormous possibilities of backtracking that your regex has, you should avoid that this (.|\n)
would capture the keyword ("test" in your example).
You could try with this to match the third word "Hello":
(?<=^(?:(?:(?!\bHello\b)[^])*\bHello\b){2}(?:(?!\bHello\b)[^])*)\bHello\b
Remove the \b
if you want to count also "Hello" in "Hellos", ...etc.