s/(?P<head>\[\[foo[^\[]*)abc/\g<head>def
s/(?=\[\[foo[^\[]*)abc/def
Which is more efficient? Are there any other ways to make it more efficient? Please note that although I used Perl-style syntax for illustration purposes, I’m actually using Python’s re library, which doesn’t allow the \K (keep) keyword.
(?P<head>\[\[foo[^\[]*)abcin python using theremodule is way faster:Outputs:
Edit (Run a few more times doing both calls in the same loop):
Outputs:
Edit (Fixing sub to match question):
Outputs:
Edit (with a string that will match the REGEX):
Output:
And one final run:
Output: