MATLAB: How to remove a part which has specific char in the beginning and in the end in string

strings

Hello,
how can I remove a part which has specific char in the beginning and in the end in string?
for example, if I have string like this:
cat dog zebra (squirrel) fish
and I want to remove a part which has '(' in the beggining and ')' in the end in order to get:
cat dog zebra fish
(without space char twice one after the other).

Best Answer

  • str = 'cat dog zebra (squirrel) fish';
    out = regexprep(str,'\s+\(.+?\)','')
    out = 'cat dog zebra fish'