Thanks
CodePudding user response:
I assume that you wish to add an asterisk to the end of each word that has a length of at least 4 that does not already end with an asterisk and is not within a string delimited with double-quotes.
Assuming your strings are well-formed in the sense that the number of double-quotes is even, you can replace the content of capture group 1 of matches of the following regular expression with an asterisk appended to the content of capture group 1:
(\w{4,})(?!\w|\*|[^"]*"(?:(?:[^"]*"{2}))*[^"]*$)
With the advice of @The fourth bird, you can improve the regex deleting (?<!")
(?<=\w)\b(?!\s[\w] ["*])(?!["*])