Could someone please help me with a regex to remove parentheses and their inner contents only when there are certain words inside, regardless of position and case of these words?
For example, if my string has parentheses with the word banana or apple inside, these parentheses and their inner contents should be removed. However, if there are other parentheses that do not have these words inside them, they should not be removed.
Example: should remove parentheses that have either the word banana or apple:
should become
Thank you very much!
Supposing you're using a regex to replace sub-strings that matches it, you can use: \([^)]*word[^)]*\)
And replace matches with an empty string.
With that regex, you find a block of parentheses that have inside the word, with any character after of before. Any character but a closed parentheses, that would mean the block already ended.