Update
Added (?<!\\) before the quantifiers, because the escaped * + must not match. Replacing will still fail if there is \\* (match \ 0 or more times).
The improvement will be
s/(?<!\\)\*(?!(?<!\\)[^[]*?(?<!\\)\])/{0,1024}/ s/(?<!\\)\+(?!(?<!\\)[^[]*?(?<!\\)\])/{1,1024}/
See here at Regexr
This means matching [*+] , but only if the closure is ahead and not [ before that. And before square brackets there is no \ (part (?<!\\) ).
(?! ... ) is a negative look
(?<! ... ) - negative lookbehind
See perlretut for more details.
Update 2 includes possessive quantifiers
s/(?<!(?<!\\)[\\+*?])\+(?!(?<!\\)[^[]*?(?<!\\)\])/{1,1024}/
See here at Regexr
It seems to work, but now it is getting really complicated!
source share