Closed azu closed 6 years ago
The page http://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead appears to have a method to prevent "catastrophic backtracking", which is the cause of this bug.
Got the correct regex: /\[(?=((?:[^\]]|\\.)*))\1\]\(((?:[^\)]|\\.)*)\)/gm
with the help of the page above. Idea: greedy capture in lookahead, then backreference to prevent backtracking.
Here is the test: https://regex101.com/r/jnZU8P/1
Update: still wrong. :-( Now the (...
part crashes.
So here is the finally correct one: /\[(?=((?:[^\]]|\\.)*))\1\]\((?=((?:[^\)]|\\.)*))\2\)/gm
And the test: https://regex101.com/r/jnZU8P/2
Test string: `abc
[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890[\1\2\34567890](\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890(\1\2\34567890`
fix #57